【问题标题】:VBA to Lotus Notes - How to Add AttachmentVBA 到 Lotus Notes - 如何添加附件
【发布时间】:2015-03-22 01:41:44
【问题描述】:

我目前正在使用下面的代码进行一些修改来创建我的消息,但添加附件功能一直很困难,有人可以帮我解决这个问题吗?

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( type%, class$, source$, [ name$ ] )

所以应该是这样的

notesEmbeddedObject = notesRichTextItem.EmbedObject(1454,"",**FILEPATH**,"")

而不是我以前的

    Call notesRichTextItem.EmbedObject(EMBED_ATTACHMENT, "", "File path")

但是我如何将它添加到消息的末尾?甚至,我将如何在代码中调用它? :(

【问题讨论】:

    标签: vba email lotus-notes attachment


    【解决方案1】:

    您应该将 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")
    

    【讨论】:

    • 请注意:由于您使用粘贴方法将 Excel 数据转换为富文本,因此您将处理后端 (NDoc) 和前端 (NUIDoc) 对象。您将不得不将上面的代码分成两部分。第一部分发生在您使用 NUIdoc 之前 - 并确保调用 NUIdoc.save(),然后第二部分发生在此之后。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多