How to add email body when mail merge from Word VBA?

533 Views Asked by At

I am trying to automate email from Word through mail merge.

Private Sub Send_EmailUsingMaiIMerge_Click()

Dim Wd_App As Word.Application
Dim Wd_Doc As Word.Document
Dim Wd_MailMerge As Word.MailMerge
Dim Data_Path As String
Dim Wd_MMFNs As Word.MailMergeFieldNames
Dim Wd_MMFN As Word.MailMergeFieldName
Dim Wd_MMDFs As Word.MailMergeDataFields
Dim Wd_MMDF As Word.MailMergeDataField

Set Wd_App = Application
Set Wd_Doc = Wd_App.Documents.Open("template.docx")
Set Wd_MailMerge = Wd_Doc.MailMerge

'Get Data Path'
Data_Path = "Sheet.xlsx"

'Give mail merge type'
Wd_MailMerge.MainDocumentType = wdFormLetters

'Lets connect to data source'
Wd_MailMerge.OpenDataSource Name:=Data_Path, SQLStatement:="SELECT * FROM [Sheet1$]"

'Lets Email using Mail Merge'
'Outlook must be open and you are connected to the internet'

Dim TotalCnt As Integer

For TotalCnt = 1 To Wd_MailMerge.DataSource.RecordCount
    Wd_MailMerge.DataSource.ActiveRecord = TotalCnt
    Wd_MailMerge.DataSource.FirstRecord = TotalCnt
    Wd_MailMerge.DataSource.LastRecord = TotalCnt
        
    'Target Mail Address Column'
    Wd_MailMerge.MailAddressFieldName = "Email"
    'Add Attachment'
    Wd_MailMerge.MailAsAttachment = True
    'Add Subject'
    Wd_MailMerge.MailSubject = "Email Subject Test"
    'Add Destination'
    Wd_MailMerge.Destination = wdSendToEmail
    
    'Execute'
    Wd_MailMerge.Execute False
    
Next TotalCnt

Wd_Doc.Close False
Set Wd_Doc = Nothing
End Sub

I can send bulk emails but without any email body. I want to add clarification before sending.

How do I add an email body or is there another approach?

1

There are 1 best solutions below

0
zerocool On

On the add attachment module just set it to False then it will send as the body of the email

'Target Mail Address Column'
    Wd_MailMerge.MailAddressFieldName = "Email"
    'Add Attachment'
    Wd_MailMerge.MailAsAttachment = False
    'Add Subject'
    Wd_MailMerge.MailSubject = "Email Subject Test"
    'Add Destination'
    Wd_MailMerge.Destination = wdSendToEmail