2017-05-18 222 views
0

我目前有一段代码段来预先填充邮件并附上当前工作表。我需要确定的是还要添加一个标准体,下面是我的代码;通过Lotus Notes填充电子邮件正文 - Excel 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 = "[email protected]" 
    Dim strsubject As String: strsubject = subj & " - " & name & " - " & dias 

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

End Sub 

感谢你的帮助,

最佳,

一个

回答

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 = "[email protected]" 
    strSubject = subj & " - " & name & " - " & dias 

    'Save the workbook 
    ThisWorkbook.Save 

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

End Sub 
相关问题