通过Lotus Notes填充电子邮件正文 - Excel VBA

时间:2017-05-18 14:35:05

标签: vba

我目前有一个小代码段来预先填充电子邮件并附加当前的工作表。我需要最终确定的是添加一个标准体,这是我的代码如下;

 Sub SDFMail()

Dim name As Variant
Dim subj As Variant

name = InputBox("Please enter name of requestor")
subj = InputBox("Please enter the subject of the service ticket")
dias = InputBox("Please enter the date in the following format DD-MM-YYYY")

    Dim strrecipient As String: strrecipient = "anthonnybelanger@gmail.com"
    Dim strsubject As String: strsubject = subj & " - " & name & " - " & dias

    Application.Dialogs(xlDialogSendMail).Show arg1:=strrecipient, arg2:=strsubject

End Sub

感谢您的帮助,

最好,

A

1 个答案:

答案 0 :(得分:0)

如果使用对话框,则没有太多选项。使用下面的代码,以便您可以轻松控制所有内容。

将代码复制并粘贴到模块中并运行它。如果这是您所需要的,请点击此问题旁边的复选标记;)

 Sub SDFMail()
    Dim strSubject As String
    Dim strRecipient As String
    Dim name As String
    Dim subj As String
    Dim dias As String

    Dim outlook As Object
    Dim outlookMail As Object

    'Define outlook object
    Set outlook = CreateObject("Outlook.Application")
    Set outlookMail = outlook.CreateItem(0)

    'Get the info from the user
    name = InputBox("Please enter name of requestor")
    subj = InputBox("Please enter the subject of the service ticket")
    dias = InputBox("Please enter the date in the following format DD-MM-YYYY")

    'Format subject
    strRecipient = "anthonnybelanger@gmail.com"
    strSubject = subj & " - " & name & " - " & dias

    'Save the workbook
    ThisWorkbook.Save

    'populate then New Email attributes
    With outlookMail
        .To = strRecipient
        .CC = "SampleCC@email.com"
        .BCC = "SampleBCC@email.com"
        .Subject = strSubject
        .Body = "This is a default body text."
        .Attachments.Add ThisWorkbook.FullName
        .Display
    End With

End Sub