Combine Multiple Word Mail Merges into One Document Using VBA
Question details
Process multiple mail-merge documents using a single Excel data source and merge their outputs into a single, portable document with section titles.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating the generation of a comprehensive document compiled from multiple distinct mail-merge templates, preserving complex fields and recipient filters.
- Observed behavior
- Generating a single consolidated document directly via VBA to maintain portability and avoid corruption issues commonly associated with Word subdocuments.
Ensure all your mail-merge main documents are stored in a dedicated subfolder and your Excel data source is accessible. Keep your files organized so the VBA script can locate them using relative paths.
Use VBA to Loop and Execute Multiple Mail Merges
Write a VBA script that prompts for the data file, iterates through the mail-merge documents, and combines their outputs sequentially.
This is the most reliable method for combining complex mail merges. It allows each document to retain unique recipient filters, IF fields, and NEXTIF fields while generating a single, portable output document.
Launch Word and press Alt + F11 to open the Microsoft Visual Basic for Applications window.
Click 'Insert' from the top menu and select 'Module' to create a blank script workspace.
Write a VBA macro that uses the FileDialog object to prompt the user for the Excel data source once. Use the Dir function to loop through all mail-merge templates stored in a subfolder relative to ThisDocument.Path.
Within the loop, configure the script to execute the mail merge for each template, copy the merged result, paste it into a new master document, and insert a section title.
End the macro by saving the generated master document as a standalone file, which can now be safely distributed in a ZIP archive.

Combine Main Documents Before Merging (Simple Merges Only)
Manually combine the contents of all mail-merge templates into a single master template before running the merge.
Perform Advanced Mail Merges Easily with WPS Writer
WPS Office provides robust built-in Mail Merge capabilities, fully supporting Excel data sources and VBA macros to automate complex, multi-document generation.
- 1. Open WPS Writer: Launch WPS Writer and navigate to the 'Mailings' tab on the top ribbon.
- 2. Connect Data Source: Click 'Open Data Source' to select and link your unified Excel spreadsheet.
- 3. Access the VBA Editor: Switch to the 'Developer' tab and click 'Macros' or 'Visual Basic' to paste and run your combination script.
- 4. Run Automation: Execute the macro to process your subfolder templates and instantly generate your consolidated document.

Frequently Asked Questions
Why not use Word's Master Document and Subdocuments feature to combine them?
Master Documents and Subdocuments rely heavily on absolute or relative paths. When files are moved, renamed, or distributed in a ZIP archive, these links often break, leading to document corruption. Generating a single new document directly via VBA ensures true portability.
Can I use different recipient filters for each of the mail-merge templates?
Yes. By using a VBA script to process the templates sequentially, each individual template can maintain its own specific IF fields, NEXTIF fields, and recipient filter rules without interfering with the others.
How do I select the Excel data source dynamically in my VBA macro?
You can use the Application.FileDialog(msoFileDialogFilePicker) method within your VBA script. This prompts the user with a standard file explorer window to select the Excel data file before the loop processing begins.
How do I insert titles between the merged outputs via VBA?
In your VBA loop, after pasting the merged output of a template into the master document, use the Selection.TypeText method to insert the title text, followed by formatting commands like Selection.Style to apply a heading style.




