Run a VBA Macro on Each Word Mail Merge Document
Question details
Run a second VBA macro on each document created by a Word mail merge.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A VBA procedure creates a separate mail merge result document for each data-source record.
- Observed behavior
- Each newly created result document needs to be active when the second macro runs.
Open the merge document in Word and identify the procedure that creates each result document and the name of the macro you want to run. Enable macros only if you trust the document and its code.
Call the second macro after each merge result is created
Use this approach when the merge procedure creates one result document per record.
In Word, press Alt+F11 to open the VBA editor, then locate the module and procedure that runs the mail merge.
In the procedure, locate the MailMerge.Execute call inside the loop that processes the records. Confirm that the merge destination creates a new document for each record.
Immediately after MailMerge.Execute, capture the newly created result document, activate it with its Activate method, and call the second macro by name before the loop advances to the next record.
Run the merge procedure with a small set of records and check each result document to confirm that the second macro changed the intended document.

Edit Word documents with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for editing Word documents. Its Microsoft Office format support makes moving everyday documents straightforward, though it does not fix or guarantee compatibility with a Word VBA mail merge procedure.

Frequently Asked Questions
Where should I call the second macro?
Place the call immediately after MailMerge.Execute inside the record loop, before processing the next record. This lets the macro run once for each newly created result.
Why does the macro run on the wrong document?
The macro may use ActiveDocument while the merge source or another document has focus. Capture and activate the new result document before calling the macro.
Can I put the macro call just before End Sub?
Yes, if the procedure creates one result per call. If it loops through several records, a call outside the loop runs only once; put it inside the loop after each merge execution instead.
How can I check that every result was processed?
Run the procedure with a small set of records, then inspect each generated document for the changes made by the second macro.




