VBA & Macro Problems

How to Split Word Mail Merge into Individual Named PDF Files

Algirdas JasaitisAlgirdas Jasaitis Oct 26, 2026 869 views

Question details

The user needs to split a Word mail merge into separate PDF files, naming each file based on a specific merge-field value and saving them to a designated folder.

How to Split Word Mail Merge Records into Individual Named PDF Files
Product
Word
Device & OS
not provided
Scenario
Saving mail merge output as multiple, individually named PDF files instead of a single continuous document.
Observed behavior
The goal is to automatically generate and route PDF documents with custom filenames (e.g., Photos_FMSFXXXX) derived from a data source during a mail merge operation.
Before you start

Ensure your Excel data source is correctly linked to your Word mail merge document and that you have enabled Developer tools in the ribbon to access the VBA editor.

Solution 1Recommended

Use a VBA Macro to Split and Save as PDFs

Modify a standard mail merge VBA macro to loop through records, apply custom filenames from merge fields, and export directly as PDFs.

By customizing a VBA script, you can automate the process of saving each merged record as an independent file. This method provides precise control over the output format, directory path, and naming conventions based on your data fields.

1
Launch the VBA Editor

Open your mail merge document in Word and press ALT + F11 to launch the VBA editor. Insert a new module for your script.

2
Define the Output Folder

In your macro code, set the output directory path. Ensure it ends with a backslash, for example: StrFolder = "C:\MyDocuments\Output\"

3
Set Custom Filenames

Build the filename string using your required data field. For example: StrName = "Photos_FMSF" & .DataFields("FMSF_No")

4
Configure the PDF Save Format

Modify the save command to output PDFs. Retain the SaveAs line with FileFormat:=wdFormatPDF and comment out or delete the DOCX SaveAs line.

5
Run the Macro

Execute the macro to process the mail merge. It will automatically loop through the data source and save the individual PDFs to your specified folder.

Use a VBA Macro to Split and Save as PDFs
Automating the Macro Execution: You can configure the macro to run automatically upon merge completion by renaming it to 'MailMergeToDoc'.
Advanced Mail Merge in WPS Office

Master Mail Merge and PDF Export with WPS Office

WPS Office provides robust Mail Merge tools and native PDF conversion features, making it easy to handle batch document creation. With its high compatibility and intuitive interface, you can seamlessly process data sources and export professional PDFs.

  1. 1. Open WPS Writer: Launch WPS Writer and open your main mail merge document template.
  2. 2. Connect Data Source: Navigate to the References tab, click Mail Merge, and select Open Data Source to link your spreadsheet.
  3. 3. Insert Merge Fields: Place your cursor in the document and use Insert Merge Field to add the dynamic data points.
  4. 4. Export to PDF: Complete the merge and use the built-in Export to PDF feature to save your batched documents securely.
Highly compatible with Microsoft Word documents and Excel data sources.Native PDF converter to easily save merged documents as high-quality PDFs.Lightweight software with an intuitive, tabbed interface.Built-in Mail Merge wizard for quick and error-free document batching.
microsoft office alternative - wps office

Frequently Asked Questions

Can I split a mail merge into separate Word files instead of PDFs?

Yes, by retaining the DOCX SaveAs command in your VBA macro instead of using the PDF format command, you can output individual .docx files.

Why are my PDF files not saving to the specified folder?

Ensure that the output folder path in your VBA code is correct, ends with a trailing backslash (e.g., "\Output\"), and that your system has write permissions for that specific directory.

Do I need programming skills to split mail merge documents?

While VBA provides a highly customizable way to split files, you can use graphical third-party tools like the Merge Tools Add-in to achieve this without manually writing or editing any code.