Add attachment to mail merge outlook 2016
To add an attachment to a mail merge in Outlook 2016, you'll need to use a combination of Outlook's built-in features and some VBA coding. Here's a step-by-step guide to help you achieve this:
Prerequisites:
- You have Outlook 2016 installed on your computer.
- You have a mail merge template set up in Microsoft Word.
- You have a list of recipients in an Excel spreadsheet or a CSV file.
Step 1: Create a new Outlook VBA project
- Open Outlook 2016 and go to the Developer tab (if you don't see the Developer tab, go to File > Options > Customize Ribbon and check the box next to "Developer").
- Click on the "Visual Basic" button in the Developer tab.
- In the Visual Basic Editor, click on "Insert" > "Module" to create a new module.
Step 2: Write the VBA code
-
In the module, paste the following code:
Sub AddAttachmentToMailMerge() Dim olApp As New Outlook.Application Dim olMail As MailItem Dim wdDoc As Document Dim wdMailMerge As MailMerge Dim wdDataSource As DataSource Dim wdRecipient As Recipient Dim strAttachment As String ' Set the path to your mail merge template strAttachment = "C:\Path\To\Your\MailMergeTemplate.docx" ' Set the path to your attachment strAttachment = "C:\Path\To\Your\Attachment.pdf" ' Create a new Outlook mail item Set olMail = olApp.CreateItem(0) ' Set the mail item's subject and body olMail.Subject = "Test Mail Merge with Attachment" olMail.Body = "This is a test mail merge with an attachment." ' Open the mail merge template Set wdDoc = olMail.GetInspector.WordEditor Set wdMailMerge = wdDoc.MailMerge wdMailMerge.OpenDataSource "C:\Path\To\Your\MailMergeTemplate.docx" ' Loop through the recipients and add the attachment For Each wdRecipient In wdMailMerge.Destination wdRecipient.AddAttachment strAttachment Next wdRecipient ' Send the mail items olMail.Send End Sub
Step 3: Modify the code
-
Update the
strAttachment
variable to point to the path of the attachment you want to add to the mail merge. -
Update the
strAttachment
variable to point to the path of your mail merge template.
Step 4: Run the VBA code
- Go back to the Outlook window and click on the "Developer" tab.
- Click on the "Run" button (or press F5) to execute the VBA code.
- The code will create a new Outlook mail item, add the attachment, and send the mail item to each recipient in your list.
Tips and Variations:
- You can modify the code to add multiple attachments by creating an array of attachment paths and looping through it.
- You can also use the
wdMailMerge.DataSource
property to specify the data source for the mail merge, instead of hardcoding the path to the mail merge template. - If you're using a CSV file as your data source, you'll need to modify the code to read the CSV file and loop through the recipients.