0

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?

Community
  • 1
  • 1
  • Why are you not using Word's mailmerge facility for this? Done that way, you can have whatever email body content you require. – macropod Jul 02 '22 at 00:17
  • @macropod any reference please – saravanan G Jul 02 '22 at 06:56
  • 1
    A basic web search turns up results like: https://support.microsoft.com/en-gb/office/use-mail-merge-to-send-bulk-email-messages-0f123521-20ce-4aa8-8b62-ac211dedefa4# – macropod Jul 05 '22 at 07:40

1 Answers1

0

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
zerocool
  • 1
  • 2