Add attachment to outlook mail merge

To add an attachment to an Outlook mail merge, you'll need to use a combination of VBA code and the Outlook Object Model. Here's a step-by-step guide to help you achieve this:

Prerequisites:

  1. You have Outlook 2010 or later version installed.
  2. You have a mail merge template set up in Microsoft Word.
  3. You have the Outlook Object Model reference added to your VBA project.

Step 1: Create a new Outlook VBA project

  1. Open Outlook and press Alt + F11 to open the Visual Basic Editor.
  2. In the Editor, click Insert > Module to create a new module.
  3. Name the module, for example, "MailMergeAttachments".

Step 2: Set up the mail merge

  1. In your Word document, go to the Mailings tab > Finish & Merge > Edit Recipient List.
  2. In the Edit Recipient List dialog box, select the recipients you want to send the email to.
  3. Click OK to close the dialog box.

Step 3: Add the attachment

  1. In the VBA Editor, add the following code to the module you created:

    Sub AddAttachmentToMailMerge()
     Dim olApp As New Outlook.Application
     Dim olMail As Outlook.MailItem
     Dim wdDoc As Word.Document
     Dim wdMailMerge As Word.MailMerge
     Dim strAttachment As String
    
     ' Set the attachment file path and name
     strAttachment = "C:\Path\To\Your\Attachment.pdf"
    
     ' Set the Word document object
     Set wdDoc = ActiveDocument
    
     ' Set the mail merge object
     Set wdMailMerge = wdDoc.MailMerge
    
     ' 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."
    
     ' Add the attachment to the mail item
     olMail.Attachments.Add strAttachment
    
     ' Send the mail item
     olMail.Send
    
     ' Clean up
     Set olMail = Nothing
     Set wdMailMerge = Nothing
     Set wdDoc = Nothing
     Set olApp = Nothing
    End Sub

    Step 4: Run the VBA code

  2. In the VBA Editor, click Run > Run Sub/User Form to execute the AddAttachmentToMailMerge subroutine.

  3. The code will create a new Outlook mail item, add the attachment, and send the email to the recipients specified in your Word document.

Tips and Variations: