[英]Sending Email with Lotus Notes - (Different Database) - Excel VBA
I have a tiny problem with a VBA that I prepared to send emails from a database in lotus notes (other than the main database) 我有一个VBA的小问题,我准备从Lotus Notes中的数据库(主数据库除外)发送电子邮件
When I send the same email from the main database in lotus notes, (username database) I have no problems, it runs smoothly. 当我从Lotus Notes的主数据库(用户名数据库)发送相同的电子邮件时,我没有问题,它运行平稳。 However, the same coding, I just change the server and the database name, it sends the emails but with a message screen in lotus notes as "do you want to save your changes?" 但是,使用相同的编码,我只是更改服务器和数据库名称,它发送电子邮件,但在Lotus Notes中显示消息屏幕为“是否要保存更改?” I need to select yes or no, then it sends the emails. 我需要选择是或否,然后它发送电子邮件。 As I said, the only difference is the database and the server in the coding. 正如我所说,唯一的区别是数据库和服务器在编码方面。
Here is the message in Lotus Notes: 这是Lotus Notes中的消息:
Here is the VBA code. 这是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")
'=> this is the main change, if I want to send from the main mail database, I don't enter anything inside the brackets and everyting works fine. '=>这是主要更改,如果要从主邮件数据库发送邮件,则无需在方括号内输入任何内容,并且一切正常。
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
The reason might be settings of the different database or I might need to code to close that message box in Lotus Notes, but I don't know how. 原因可能是不同数据库的设置,或者我可能需要编写代码以关闭Lotus Notes中的该消息框,但是我不知道如何。
It's hard to say, but one database may have a different default form than the other, and your code may be using it. 很难说,但是一个数据库的默认形式可能与另一个数据库不同,并且您的代码可能正在使用它。 I'd suggest adding a field on the Notes document called SaveOptions and set the value to 0. Try: 我建议在Notes文档上添加一个名为SaveOptions的字段,并将其值设置为0。尝试:
NUIDoc.Document.ReplaceItemValue("SaveOptions",0)
before sending. 在发送之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.