2017-05-18 136 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 
相關問題