VBA & Macro Problems

Run a VBA Macro on Each Word Mail Merge Document

Khadija KhanKhadija Khan Nov 22, 2026 868 views

Question details

Run a second VBA macro on each document created by a Word mail merge.

Run a VBA Macro on Each Word Mail Merge Document
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.
Before you start

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.

Solution 1Recommended

Call the second macro after each merge result is created

Use this approach when the merge procedure creates one result document per record.

1
Open the VBA procedure

In Word, press Alt+F11 to open the VBA editor, then locate the module and procedure that runs the mail merge.

2
Find the merge execution

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.

3
Activate the result and call the macro

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.

4
Test each result

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.

Call the second macro after each merge result is created
Place the call inside the loop: A call immediately before End Sub runs only once if it is outside the record loop. If the procedure itself is called once per record, placing the call before End Sub can work, provided the result document is active.
Free Microsoft Office alternative

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.

Edit mail merge output documents in WPS WriterOpen and edit Microsoft Word DOCX filesUse a familiar interface for everyday document workGet a free, lightweight Office alternative
microsoft office alternative - wps office

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.