发送带附件的电子邮件[Lotus Notes]

时间:2015-09-20 04:32:15

标签: excel vba excel-vba email

我有两个Excel文件:一个是启用宏的,一个是空白的Excel表单。

方案: - 目前,Blank Excel表单将手动填写并附加在Lotus Notes电子邮件中,并每天从外部发送。 - 此Excel空白表单一旦填充信息,也将另存为具有不同文件名的新Excel文件。

现在,我想编写VBA Excel,这样我只需要点击按钮发送Lotus Notes电子邮件中附带的Excel表单。

我已经发现代码如下,它正在运行:

Sub Send_Email_via_Lotus_Notes()
Dim Maildb As Object
Dim MailDoc As Object
Dim Body As Object
Dim Session As Object
'Start a session of Lotus Notes
    Set Session = CreateObject("Lotus.NotesSession")
'This line prompts for password of current ID noted in Notes.INI
    Call Session.Initialize
'or use below to provide password of the current ID (to avoid Password prompt)
    'Call Session.Initialize("<password>")
'Open the Mail Database of your Lotus Notes
    Set Maildb = Session.GETDATABASE("", "D:\Notes\data\Mail\eXceLiTems.nsf")
    If Not Maildb.IsOpen = True Then Call Maildb.Open
'Create the Mail Document
    Set MailDoc = Maildb.CREATEDOCUMENT
    Call MailDoc.REPLACEITEMVALUE("Form", "Memo")
'Set the Recipient of the mail
    Call MailDoc.REPLACEITEMVALUE("SendTo", "Ashish Jain")
'Set subject of the mail
    Call MailDoc.REPLACEITEMVALUE("Subject", "Subject Text")
'Create and set the Body content of the mail
    Set Body = MailDoc.CREATERICHTEXTITEM("Body")
    Call Body.APPENDTEXT("Body text here")
'Example to create an attachment (optional)
    Call Body.ADDNEWLINE(2)
    Call Body.EMBEDOBJECT(1454, "", "C:\dummy.txt", "Attachment")
'Example to save the message (optional) in Sent items
    MailDoc.SAVEMESSAGEONSEND = True
'Send the document
'Gets the mail to appear in the Sent items folder
    Call MailDoc.REPLACEITEMVALUE("PostedDate", Now())
    Call MailDoc.SEND(False)
'Clean Up the Object variables - Recover memory
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set Body = Nothing
    Set Session = Nothing

但是,我希望附件文件名和电子邮件主题可变,而不是硬编码静态文件名和路径。

有人请提供一些指导吗?

1 个答案:

答案 0 :(得分:2)

使用参数。

YES