首页 文章

使用 Lotus Notes 发送电子邮件-(不同的数据库)-Excel VBA

提问于
浏览
1

我有一个 VBA 的小问题,我准备从 Lotus Notes 中的数据库(主数据库除外)发送电子邮件

当我从 Lotus Notes 的主数据库(用户名数据库)发送相同的电子邮件时,我没有问题,它运行平稳。但是,使用相同的编码,我只是更改服务器和数据库名称,它发送电子邮件,但在 Lotus Notes 中显示消息屏幕为“是否要保存所做的更改?”。我需要选择是或否,然后它发送电子邮件。正如我所说,唯一的区别是数据库和服务器在编码方面。

这是 Lotus Notes 中的消息:

在此处输入图片说明

这是 VBA 代码。

Sub SendWithLotus()
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("XXXXX/XXX/XXXServer", "mail\YYYYY")

'=>这是主要更改,如果要从主邮件数据库发送邮件,则无需在方括号内输入任何内容,并且一切正常。

If Not NDatabase.IsOpen Then
    NDatabase.OPENMAIL
End If

'Create a new document

Set NDoc = NDatabase.CREATEDOCUMENT

With NDoc
    .SendTo = Range("O8").Value
    .CopyTo = ""
    .Subject = Range("O7").Value

    'Email body text, including marker text which will be replaced by the Excel cells

    .body = vbNewLine & vbNewLine & _
        "**Cell Contents**" & vbNewLine & vbNewLine & _
        ""

    .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 "**Cell Contents**"
    '.DESELECTALL            'Uncomment to leave the marker text in place (cells are inserted immediately before)

    'Replace it with the Excel cells

    Sheets("Sheet1").Range("A1:L58").CopyPicture xlScreen, xlBitmap
    .Paste
    Application.CutCopyMode = False
    .Send
    .Close
    NDoc.SAVEMESSAGEONSEND = True
End With

Set NSession = Nothing
    NDatabase = Nothing
    NDoc = Nothing
End Sub

原因可能是不同数据库的设置,或者我可能需要编写代码以关闭 Lotus Notes 中的该消息框,但是我不知道如何。

1 回答

  • 0

    很难说,但是一个数据库的默认形式可能与另一个数据库不同,并且您的代码可能正在使用它。我建议在 Notes 文档上添加一个名为 SaveOptions 的字段,并将其值设置为 0。尝试:

    NUIDoc.Document.ReplaceItemValue("SaveOptions",0)
    

    在发送之前。

相关问题