对富文本域进行两个简单的操作

1、下载富文本域所带的附件

Sub Initialize
	On Error GoTo errhandle
	
	Dim session As New NotesSession
	Dim ws As New NotesUIWorkspace
	Dim db As NotesDatabase
	Dim dc As NotesDocumentCollection
	Dim doc As NotesDocument
	Dim rtitem As NotesRichTextItem
	Dim tmpStr As String
	Dim specialCharacters As Variant,filepath As Variant
	
	初始化变量
	Set db = session.Currentdatabase
	获取选择文档的集合
	Set dc = db.Unprocesseddocuments
	If dc.Count = 0 Then
		Exit sub
	End If
	
	选择存放路径
	filepath = ws.SaveFileDialog( True,"选择文件夹路径:",, "e:", "")
	If IsEmpty(filepath) Then
		Exit Sub
	End If

	循环文档
	Dim i As Integer,count As Integer
	count = 0
	For i = 1 To dc.Count
		Set doc = dc.Getnthdocument(i)
		获取存放附件的字段
		Set rtitem = doc.Getfirstitem("Memo")
		If (rtitem.Type = RICHTEXT) Then
			判断字段内是否有值
			If Not IsEmpty(rtitem.Embeddedobjects) Then
				
				ForAll o In rtitem.Embeddedobjects
					判断是否为附件类型
					If (o.Type = EMBED_ATTACHMENT) Then
						count = count + 1
						Call o.ExtractFile(filepath(0) & "" & o.name & "_" & count & ".txt")
						
						删除文档上的附件,慎重
						Call o.Remove
					End If
				End ForAll
				
				保存文档
				Call doc.Save(True, False)
			End If
		End If
	Next
	
	Exit Sub
errhandle:
	MsgBox Erl & Error
	Exit sub
End Sub

2、上传附件到富文本域

Sub Initialize
	On Error GoTo errhandle
	
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim dc As NotesDocumentCollection
	Dim doc As NotesDocument
	Dim rtitem As NotesRichTextItem
	Dim object As NotesEmbeddedObject
	
	初始化变量
	Set db = session.Currentdatabase
	Set dc = db.Unprocesseddocuments
	If dc.Count = 0 Then
		Exit sub
	End If
	
	循环文档
	Dim i As Integer
	For i = 1 To dc.Count
		Set doc = dc.Getnthdocument(i)
		Set rtitem = doc.Getfirstitem("Memo")
		If rtitem Is Nothing Then
			Set rtitem = New NotesRichTextItem(doc,"Memo")
		End If
		
		Set object = nothing
		上传附件
		Set object = rtitem.Embedobject(EMBED_ATTACHMENT,"", "e:
ewfileExcel表.txt")
		If Not object Is Nothing Then
			Call doc.Save(true, false)
		End If
	Next
	
	Exit Sub
errhandle:
	MsgBox Erl & Error
	Exit sub
End Sub
经验分享 程序员 微信小程序 职场和发展