logo
search
VBA & Macro Problems

Combine Multiple Word Mail Merges into One Document Using VBA

Maira MehtabMaira Mehtab Oct 10, 2026 869 views

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.

Combine Multiple Word Mail Merges into One Document Using VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Launch Word and press Alt + F11 to open the Microsoft Visual Basic for Applications window.

2
Insert a New Module

Click 'Insert' from the top menu and select 'Module' to create a blank script workspace.

3
Write the File Prompt and Loop Script

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.

4
Execute and Consolidate

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.

5
Save the Output

End the macro by saving the generated master document as a standalone file, which can now be safely distributed in a ZIP archive.

Use VBA to Loop and Execute Multiple Mail Merges
Why this works best: Direct document generation via VBA avoids the relative path breakage common with Word subdocuments and reliably handles complex IF or NEXTIF fields during the merge.
Efficient Mail Merge Automation

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. 1. Open WPS Writer: Launch WPS Writer and navigate to the 'Mailings' tab on the top ribbon.
  2. 2. Connect Data Source: Click 'Open Data Source' to select and link your unified Excel spreadsheet.
  3. 3. Access the VBA Editor: Switch to the 'Developer' tab and click 'Macros' or 'Visual Basic' to paste and run your combination script.
  4. 4. Run Automation: Execute the macro to process your subfolder templates and instantly generate your consolidated document.
Full compatibility with Microsoft Word documents and Excel data sources.Supports complex IF, NEXTIF fields, and customized recipient filters flawlessly.Advanced VBA and Macro support to seamlessly run your custom automation scripts.Lightweight, fast, and free to download.
microsoft office alternative - wps office

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.