这是我写过的一段 将office附件转换成mht代码 转换代码我就不贴出来了 下面的代码是处理附件的过程
其中 newFile 和aFileName 是文件的绝对路径 changWord()和changExcel() 是处理我文件转换的代码返回一个文件绝对路径 你分析一下下面的代码 你的问题能解决
Dim session As New NotesSession
Dim doc As NotesDocument
Dim embedobject As NotesEmbeddedObject
Dim aFileName As String
Set doc = session.DocumentContext
Dim mhtdb As New NotesDatabase("","weboa/common/docAttach.nsf")
Dim tview As NotesView
Dim ritem As NotesRichTextItem
Dim docmht As NotesDocument
Dim UID As String
Dim filetype As String
Dim newFile As String
'1,得到当前文档所有的附近
Dim v As Variant
v = Evaluate(|@AttachmentNames|,doc)
Forall x In v
Set embedobject = doc.GetAttachment(Cstr(x))
'3,判断文件的类型
filetype=Lcase(Strrightback(aFileName,"."))
'4,根据类型 进行相应的转换
If filetype = "doc" Then
newFile = changWord(afileName)
Elseif filetype = "xls" Then
newFile = changExcel(afileName)
Else
newFile = ""
End If
If newFile <> "" Then
'5,将转换的文件上传到文档库中
Set docmht = mhtdb.CreateDocument
Call docmht.AppendItemValue("form","Attach")
Call docmht.AppendItemValue("DBPath","weboa/zongbu/docAttach.nsf")
Call docmht.AppendItemValue("DBDIr","weboa/zongbu")
Set ritem = docmht.GetFirstItem("Attachment")
If ritem Is Nothing Then
Set ritem = docmht.CreateRichTextItem("Attachment")
Elseif ritem.type <> RICHTEXT Then
Call docmht.RemoveItem( "Attachment" )
Set ritem = New NotesRichTextItem(docmht, "Attachment" )
End If
Set embedobject = docmht.GetAttachment(Strrightback(newFile,"\"))
If Not embedobject Is Nothing Then
Call embedobject.Remove()
End If
ritem.EmbedObject EMBED_ATTACHMENT,"",newFile
Call docmht.Save(True,False)
UID = docmht.UniversalId