我目前正在使用下面的代码进行一些修改来创建我的消息,但是添加附件功能一直很困难,有人可以帮我解决这个问题吗?
Sub Notes_Email_Excel_Cells()
Dim NSession As Object
Dim NDatabase As Object
Dim NUIWorkSpace As Object
Dim NDoc As Object
Dim NUIdoc As Object
Set NSession = CreateObject("Notes.NotesSession")
Set NUIWorkSpace = CreateObject("Notes.NotesUIWorkspace")
Set NDatabase = NSession.GetDatabase("", "")
If Not NDatabase.IsOpen Then
NDatabase.OPENMAIL
End If
'Create a new document
Set NDoc = NDatabase.CreateDocument
With NDoc
.SendTo = "email.address@email.com"
.CopyTo = ""
.subject = "Pasted Excel cells " & Now
'Email body text, including marker text which will be replaced by the Excel cells
.body = "Text in email body" & vbNewLine & vbNewLine & _
"**PASTE EXCEL CELLS HERE**" & vbNewLine & vbNewLine & _
"Excel cells are shown above"
.Save True, False
End With
'Edit the just-created document to copy and paste the Excel cells into it
Set NUIdoc = NUIWorkSpace.EDITDocument(True, NDoc)
With NUIdoc
'Find the marker text in the Body item
.GotoField ("Body")
.FINDSTRING "data"
'Replace it with the Excel cells
Sheets("Sheet1").Range("A1:E6").Copy
.Paste
Application.CutCopyMode = False
'.Send
'.Close
End With
Set NSession = Nothing
End Sub
我相信我可能会有一些成功添加以下几行,但我仍然需要在工作中测试它,因为我是从我的PC上发布的:
Dim notesRichTextItem As NotesRichTextItem
'[...]
Set notesRichTextItem = doc.CreateRichTextItem("Body")
'[...]
Call notesRichTextItem.EmbedObject(EMBED_ATTACHMENT, "", "File path")
我还没有真正了解EmbedObject参数,因为我在IBM知识中心发现的内容并没有清除我的所有疑虑(here),正如您在下面找到的那样
在
中定义NotesRichTextItem
语法
设置notesEmbeddedObject = notesRichTextItem.EmbedObject(类型%,类$,源$,[名称$])
因此它应该像
notesEmbeddedObject = notesRichTextItem.EmbedObject(1454,"",**FILEPATH**,"")
而不是我之前的
Call notesRichTextItem.EmbedObject(EMBED_ATTACHMENT, "", "File path")
但是如何将其添加到邮件的末尾?或者甚至,我将如何在代码中调用它? :(
答案 0 :(得分:0)
您应该将Body
字段的初始化转换为NotesRichTextItem
初始化
而不是:
.body = "Text in email body" & vbNewLine & vbNewLine & _
"**PASTE EXCEL CELLS HERE**" & vbNewLine & vbNewLine & _
"Excel cells are shown above"
写下这个:
Set notesRichTextItem = .CreateRichTextItem("Body")
notesRichTextItem.AppendText("Text in email body")
notesRichTextItem.AddNewline(2)
notesRichTextItem.AppendText("**PASTE EXCEL CELLS HERE**")
notesRichTextItem.AddNewline(2)
notesRichTextItem.AppendText("Excel cells are shown above")
notesRichTextItem.AddNewline(1)
'And here comes the attachment:
Call notesRichTextItem.EmbedObject(EMBED_ATTACHMENT, "", "File path")