You need to send personalized documents to many recipients, but each person must receive their own PDF file. A standard mail merge in Word produces a single merged document with all records on separate pages. Splitting that combined PDF manually takes too long when you have hundreds of recipients. This article explains how to use a Word macro to run a mail merge and save each record as a separate PDF file automatically. You will learn the exact steps to set up the merge, run the VBA code, and handle common errors.
Key Takeaways: Mail Merge to Individual PDFs in Word
- Mailings > Start Mail Merge > Step-by-Step Mail Merge Wizard: Prepares the main document and connects it to your data source.
- Alt+F11 to open the VBA editor: Where you paste the macro that loops through each record and exports a single PDF.
- ActiveDocument.MailMerge.DataSource.ActiveRecord and ExportAsFixedFormat: The two VBA methods that iterate records and save each one as a PDF file.
How the Macro-Based Mail Merge to PDF Works
The standard mail merge feature in Word merges all records into one document. To get one PDF per recipient, you need a Visual Basic for Applications macro that performs the merge one record at a time. The macro loops through each data source record, executes the merge for that single record, and calls the ExportAsFixedFormat method to save the result as a PDF. After saving, it closes the merged document without saving changes and moves to the next record. This process requires a properly set up main document with merge fields and a connected data source such as an Excel spreadsheet, Outlook contacts, or an Access database. No third-party software is needed.
Prerequisites
Before running the macro, confirm the following:
- Your main document contains all merge fields and is saved on your local drive or network.
- Your data source is connected and accessible. For Excel, the workbook must be closed during the merge or the macro may fail.
- You have permission to create files in the output folder you specify in the macro.
- Macros are enabled in Word. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Enable all macros or Enable VBA macros. Disable macro notification if desired.
Steps to Set Up the Mail Merge and Run the VBA Macro
Follow these steps in order. Do not skip the mail merge setup — the macro will produce blank PDFs if the main document has no merge fields or data connection.
Step 1: Prepare Your Main Document and Data Source
- Create or open the main document
Open a new blank document or an existing template. On the Mailings tab, click Start Mail Merge and choose Letters, E-mail Messages, or Directory depending on your output type. Letters is the most common choice for individual PDFs. - Connect the data source
Click Select Recipients > Use an Existing List. Browse to your Excel file, Access database, or Outlook Contacts. If using Excel, select the worksheet that contains your column headers. In the Select Table dialog, confirm that the First row of data contains column headers box is checked. - Insert merge fields
Place your cursor where each field should appear. Click Insert Merge Field and choose the column name from the list. Repeat for all fields such as First Name, Last Name, Address, etc. Add any static text and formatting around the fields. - Preview and save the document
Click Preview Results on the Mailings tab to verify that data appears correctly. Save the document with a descriptive name. This is the file the macro will use as the source.
Step 2: Open the VBA Editor and Insert the Macro
- Open the VBA editor
Press Alt+F11 on your keyboard. In the Project Explorer pane on the left, find your document name listed under Normal or Project. If Project Explorer is not visible, press Ctrl+R to show it. - Insert a new module
Right-click anywhere inside the Project pane under your document name. Choose Insert > Module. A blank code window opens. - Paste the macro code
Copy the following macro and paste it into the module window:
Sub MailMergeToIndividualPDFs()
Dim MainDoc As Document
Dim DataSource As MailMergeDataSource
Dim i As Long
Dim RecordCount As Long
Dim OutputFolder As String
Dim FileName As String
Set MainDoc = ActiveDocument
Set DataSource = MainDoc.MailMerge.DataSource
OutputFolder = "C:\PDFOutput\"
' Change the path above to your desired folder. Include trailing backslash.
If Dir(OutputFolder, vbDirectory) = "" Then
MsgBox "Output folder does not exist: " & OutputFolder & vbCrLf & _
"Create the folder or change the path in the macro.", vbExclamation
Exit Sub
End If
RecordCount = DataSource.RecordCount
For i = 1 To RecordCount
DataSource.ActiveRecord = i
If DataSource.ActiveRecord = wdNoDataLine Then
GoTo NextRecord
End If
With MainDoc.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
End With
FileName = OutputFolder & "Recipient_" & i & ".pdf"
' Change the file naming pattern above if needed. You can use merge fields.
ActiveDocument.ExportAsFixedFormat _
OutputFileName:=FileName, _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
NextRecord:
Next i
MsgBox "Mail merge complete. PDFs saved to " & OutputFolder, vbInformation
End Sub
Edit the OutputFolder path to match your system. Use a folder you have write access to. The example names files Recipient_1.pdf, Recipient_2.pdf, and so on. You can change the FileName line to use a merge field value, for example: FileName = OutputFolder & DataSource.DataFields("LastName").Value & "_" & DataSource.DataFields("FirstName").Value & ".pdf". Make sure the field names match your column headers exactly.
Step 3: Run the Macro
- Close the VBA editor
Press Alt+Q or click the Close button. You return to your main document. - Run the macro
Press Alt+F8 to open the Macros dialog. Select MailMergeToIndividualPDFs from the list and click Run. Word processes each record, creates a merged document for that single record, exports it as a PDF, and closes the merged document. A message box appears when all PDFs are created. - Check the output folder
Open the folder you set in the macro. Verify that the PDFs exist and contain the correct personalized content.
Common Problems When Running the Macro
Macro Produces Blank PDFs
The main document has no data connection or the data source is not selected. Go to Mailings > Select Recipients and verify your list is attached. Preview Results should show data before you run the macro. If the data source is an Excel file, make sure the file is closed during the macro run.
Error 5152: Cannot Save File
The output folder does not exist or you do not have write permissions. Create the folder manually or change the OutputFolder path in the macro to an existing location such as your desktop. Use a path with no spaces if possible.
Only the First Record Is Merged
The macro may stop if the data source contains empty rows or if the ActiveRecord property fails to advance. Check that your data source has no blank rows between records. Add an On Error Resume Next line after the For i line if the issue persists, but test carefully.
Word Appears to Hang or Slow Down
Processing hundreds of records can take several minutes. The macro opens and closes a new document for each record. To speed up the process, disable screen updating by adding Application.ScreenUpdating = False at the start of the macro and Application.ScreenUpdating = True before the final MsgBox line.
Macro Method vs Manual Save As PDF
| Item | Macro Method | Manual Save As PDF |
|---|---|---|
| Time for 100 records | 2–5 minutes | 20–40 minutes |
| Risk of human error | Low | High |
| File naming flexibility | Customizable via VBA | Manual rename each file |
| Requires VBA knowledge | Yes, copy-paste only | No |
| Works with any data source | Yes | Yes, but manual splitting |
The macro method is the only practical way to produce one PDF per recipient from a mail merge in Word without third-party tools. Manual splitting after a standard merge is error-prone and slow for more than a handful of records.
You can now run a mail merge that outputs individual PDF files for every recipient in your data source. Test the macro with a small set of three to five records first. After confirming the output, adjust the file naming pattern to include recipient names instead of numbers. For advanced use, modify the macro to save to a network folder or to add date stamps in the file name.