How do I do a mail merge with different PDF attachments?

Updated on November 4, 2021

Mail Merge is one of the most efficient features in Microsoft Office: you can design your document in Word, with smart text formatting, fonts, and images – and send your text in individual messages via Outlook. You can use Outlook Contacts, or an external data file (Excel, Access, .csv, or a text file) as your recipient data source, and add fields from your data file into your message text to personalize your message. The regular Mail Merge feature in Word allows you to select 3 formats: HTML-message, Plain Text, or attach your individual document to messages.

How do I do a mail merge with different PDF attachments?

With a similar “E-Mail Merge” feature in Microsoft Office Publisher, you can send your personalized publications as designer’s HTML-messages through Outlook as well.

These message formats are very popular – but sometimes your HTML-message text may be incorrectly formatted and displayed on the recipients’ devices, images may be lost or attached to your message as separate files, the recipients may fail to open your attached document on their mobile devices…

Mail Merge: send personalized PDF files in Word

All these issues can be avoided if you just have a possibility to use Mail Merge with PDF attachments, i.e. attach your merged message as an individual PDF file – and our extension for Word, Outlook, and Publisher, the Mail Merge Toolkit add-in, provides such selection for Microsoft Office 2019, 2016, 2013 and 2010 (where converting to PDF files is supported).

If you send your messages from Mail Merge in PDF attachments, all your recipients get personalized PDF-files with your text and all images, looking exactly like you designed your document or publication.

We added two PDF formats in Mail Merge Toolkit (this feature is available in the PRO edition of the app): “PDF Attachment optimized for viewing” and “PDF Attachment optimized for printing”, so that your mail recipients can also print your messages:

How do I do a mail merge with different PDF attachments?

If you send your mail as PDF files, your recipients may even edit such messages with their PDF-editors.

You will be also offered to type your short message text in a separate dialogue window – so that your merged messages with PDF attachments are not empty, and contain personal salutations to all your recipients in the message body as well.

Attach individual PDF documents as attachments in mail merge

You are welcome to see this short video, that shows the described feature of the Mail Merge Toolkit app in details:

How do I do a mail merge with different PDF attachments?

Using this efficient feature, you can send personalized documents, orders and invoices in PDF format within a single mailing: just design your document or publication, add fields from your database to your message – and Mail Merge Toolkit will generate and send messages with individual nice-looking PDF attachments to your recipients!

Learn more about other features of Mail Merge Toolkit or download and try it yourself.

How do I do a mail merge with different PDF attachments?

Convert your Word Mail Merge into separate PDF documents! No third-party plug-in, no complexity, and no need to go moving and renaming documents.

Introduction

You would think that converting a mail merge to separate PDF documents would be easy. However, a quick search gives up solutions which are either ridiculously complex or require a third-party plug-in (often paid for). Worst of all, even if you get that to work you will end up with a folder containing a load of files named something completely useless like document 1, document 2, document 159. You will then spend a day renaming files before you can email them out or file them away.

So we avoid all those problems and give you a one-button solution which handles the whole thing, saving your PDF files with the names you want and in the folders you want (you can even have different folders for different files).

This is done using a Word Macro, the text of which is below. Read on, or watch the video, to find out how to add the macro to Word, set up your mail merge and then sit back as the computer does the work for you.

The Video

The Super Quick Version

  • Copy the text of the Macro from below and add to Word.
  • Add the following fields to your Mail Merge data: DocFolderPath, DocFileName, PdfFolderPath, PdfFileName. 
  • In the FileName fields, put the file names you want for the separated Word Docs and converted PDFs. No need to include the extensions.
  • In the FolderPath fields put valid folder paths (e.g. C:\Users\me\Documents). These can be the same for all rows, or different – the choice is yours.
  • Create your Mail Merge. 
  • Run the Macro
  • Sit back and let the computer work.

The Macro

******     UPDATE! – Windows code updated from what is shown in the video     ******

******     UPDATE! – Mac code now added     ******

Code for Windows

				
					Sub MailMergeToPdfBasic()                                                        ' Mark the start of the Subroutine (i.e. Macro) and name it "MailMergeToPdf"
' Macro created by Imnoss Ltd
' Please share freely while retaining attribution
' Last Updated 2021-05-03
    Dim masterDoc As Document, singleDoc As Document, lastRecordNum As Long   ' Create variables ("Post-it Notes") for later use
    Set masterDoc = ActiveDocument                                               ' Identify the ActiveDocument (foremost doc when Macro run) as "masterDoc"
    
    masterDoc.MailMerge.DataSource.ActiveRecord = wdLastRecord                   ' jump to the last active record (active = ticked in edit recipients)
    lastRecordNum = masterDoc.MailMerge.DataSource.ActiveRecord                  ' retrieve the record number of the last active record so we know when to stop
    
    masterDoc.MailMerge.DataSource.ActiveRecord = wdFirstRecord                  ' jump to the first active record (active = ticked in edit recipients)
    Do While lastRecordNum > 0                                                   ' create a loop, lastRecordNum is used to end the loop by setting to zero (see below)
        masterDoc.MailMerge.Destination = wdSendToNewDocument                    ' Identify that we are creating a word docx (and no e.g. an email)
        masterDoc.MailMerge.DataSource.FirstRecord = masterDoc.MailMerge.DataSource.ActiveRecord              ' Limit the selection to just one document by setting the start ...
        masterDoc.MailMerge.DataSource.LastRecord = masterDoc.MailMerge.DataSource.ActiveRecord               ' ... and end points to the active record
        masterDoc.MailMerge.Execute False                                        ' run the MailMerge based on the above settings (i.e. for one record)
        Set singleDoc = ActiveDocument                                           ' Identify the ActiveDocument (foremost doc after running the MailMerge) as "singleDoc"
        singleDoc.SaveAs2 _
            FileName:=masterDoc.MailMerge.DataSource.DataFields("DocFolderPath").Value & Application.PathSeparator & _
                masterDoc.MailMerge.DataSource.DataFields("DocFileName").Value & ".docx", _
            FileFormat:=wdFormatXMLDocument                                      ' Save "singleDoc" as a word docx with the details provided in the DocFolderPath and DocFileName fields in the MailMerge data
        singleDoc.ExportAsFixedFormat _
            OutputFileName:=masterDoc.MailMerge.DataSource.DataFields("PdfFolderPath").Value & Application.PathSeparator & _
                masterDoc.MailMerge.DataSource.DataFields("PdfFileName").Value & ".pdf", _
            ExportFormat:=wdExportFormatPDF                                      ' Export "singleDoc" as a PDF with the details provided in the PdfFolderPath and PdfFileName fields in the MailMerge data
        singleDoc.Close False                                                    ' Close "singleDoc", the variable "singleDoc" can now be used for the next record when created
        If masterDoc.MailMerge.DataSource.ActiveRecord >= lastRecordNum Then     ' test if we have just created a document for the last record
            lastRecordNum = 0                                                    ' if so we set lastRecordNum to zero to indicate that the loop should end
        Else
            masterDoc.MailMerge.DataSource.ActiveRecord = wdNextRecord           ' otherwise go to the next active record
        End If
    
    Loop                                                                         ' loop back to the Do start
End Sub                                                                          ' Mark the end of the Subroutine

				
			

Code for Mac

				
					Sub MailMergeToPdf()                                                        ' Mark the start of the Subroutine (i.e. Macro) and name it "MailMergeToPdf"
    Dim masterDoc As Document, recordNum As Long, singleDoc As Document  ' Create variables ("Post-it Notes") for later use
    Set masterDoc = ActiveDocument                                          ' Identify the ActiveDocument (foremost doc when Macro run) as "masterDoc"
    
    masterDoc.MailMerge.DataSource.ActiveRecord = wdLastRecord
    
    For recordNum = 1 To masterDoc.MailMerge.DataSource.ActiveRecord         ' Set "recordNum" to 1 and start loop | second part defines end point for loop
        masterDoc.MailMerge.DataSource.ActiveRecord = recordNum             ' Change the active record in the MailMerge to the "recordNum"
        masterDoc.MailMerge.Destination = wdSendToNewDocument               ' Identify that we are creating a word docx (and no e.g. an email)
        masterDoc.MailMerge.DataSource.FirstRecord = recordNum              ' Limit the selection to just one document by setting the start ...
        masterDoc.MailMerge.DataSource.LastRecord = recordNum               ' ... and end points to the same number (which is the same as the active record)
        masterDoc.MailMerge.Execute False                                   ' run the MailMerge based on the above settings (i.e. for one record)
        Set singleDoc = ActiveDocument                                      ' Identify the ActiveDocument (foremost doc after running the MailMerge) as "singleDoc"
        singleDoc.SaveAs _
            FileName:=masterDoc.MailMerge.DataSource.DataFields("DocFolderPath").Value & "/" & _
                masterDoc.MailMerge.DataSource.DataFields("DocFileName").Value & ".docx", _
            fileFormat:=wdFormatXMLDocument                                 ' Save "singleDoc" as a word docx with the details provided in the DocFolderPath and DocFileName fields in the MailMerge data
        singleDoc.SaveAs _
            FileName:=masterDoc.MailMerge.DataSource.DataFields("PdfFolderPath").Value & "/" & _
                masterDoc.MailMerge.DataSource.DataFields("PdfFileName").Value & ".pdf", _
            fileFormat:=wdFormatPDF                                              ' Export "singleDoc" as a PDF with the details provided in the PdfFolderPath and PdfFileName fields in the MailMerge data
        singleDoc.Close False                                               ' Close "singleDoc", the variable "singleDoc" can now be used for the next record when created
    Next recordNum                                                          ' Add one to "recordNum" and return to the beginning of the loop (line under "For recordNum = 1 ..."
End Sub                                                                     ' Mark the end of the Subroutine

				
			

The Long Version

Adding the Macro

To add a macro to Word you will need to be able to see the Developer tab. If you don’t have this appearing, that’s perfectly normal for Word, they hide it by default. To make it appear is you just right-click anywhere in the ribbon and select “Customise the Ribbon”. In the dialogue box which appears make sure the checkbox next to Developer in the right-hand column is checked. Once done press Ok, and the Developer tab will appear in the Ribbon. This contains the Visual Basic and Macro buttons on the left-hand side.

Click the Visual Basic button in the Developer tab to open the Visual Basic editor where we will add our macro. If you do not see a window called “Project” then click on the View menu and select “Project Explorer”. This will bring up the Project window. In this window right-click on “Normal” and in the contextual menu select “Insert” and then “Module”. A new file called “Module1” will appear in the Modules folder under “Normal” (the file may have a different number if Module1 already exists).

The middle of the window will be a white canvas – this is the editing space for the new module. Copy the Macro from this article and paste it into the middle of the VBA editor.

Preparing the Data

Start by preparing your data exactly as you would for a normal mail merge – i.e. a sheet in Excel with headers in the first row and data underneath.

For the macro to work, you will need to add in four extra columns named: DocFolderPath, DocFileName, PdfFolderPath, and PdfFileName. These should be exactly as written here, with no spaces and each word capitalised.

The fields DocFolderPath and PdfFolderPath should contain paths to folders which exist on your system. If you have a suitable folder open you can click in the address bar and copy the folder path from there. The folder paths may be the same or different for different rows. If you wish, you can generate folder paths using formulas. You will need to make sure that each folder exists for the macro to work.

The fields DocFileName and PdfFileName should contain a name for the Word doc and PDF file respectively. If the files are all going into the same folder, the names need to be unique to avoid overwriting. These can be created by copying and pasting e.g. a name, or generated by a formula as shown in the images. There is no need to add an extension (.docx or .pdf).

Word requires that a Word document be saved before converting to PDF so we have to save the Word documents, even if you don’t want them.

Preparing the Mail Merge Template

Prepare your mail merge template as you would any other mail merge. The four extra fields can be ignored unless you want them to appear in the mail merge (I guess you might want the file name to appear in the header). 

How do I do a mail merge with different PDF attachments?
Prepare your mail merge template in Word as for a normal mail merge - there is no need to add the extra fields anywhere

Running the Mail Merge to PDF

In the Developer tab click the “Macros” button. Select the macro “MailMergeToPdf” and click Run. 

Sit back and let the magic happen.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.

How do you attach multiple PDF files to a mail merge?

Open MS Word -> Prepare the mail merge document. Go to Mailings tab -> Click on Start Mail Merge and then Select Letters. Click on “Select Recipients” and choose your data source (CSV or Excel File) Click on Insert Merge Fields and customize the document as desired.

How do I mail merge with different attachments?

Send multiple attachments to each recipient.
Open the Google spreadsheet for the mail merge..
In Google Sheets, select Add-ons > Yet Another Mail Merge > Start Mail Merge..
Click + Alias, filters, personalized attachments..
Select Attach files in column “...” to emails sent, and click Back..
Click Send emails..

Can you include attachments in a mail merge?

You can't directly attach files in Microsoft Word mail merge. Instead, you'll need third-party Add-ins like the “Outlook Mail Merge Attachment (OMMA),” “Merge Tools Add-In,” or “Mail merge toolkit.”

Can you include a PDF in a mail merge?

Can you mail merge a PDF? Yes, using pdfMachine you can mail merge a PDF. pdfMachine ultimate working with the Microsoft Word mail merge feature emails the documents from the Word mail merge in PDF format.