Document Editing Problems

Capture a Merged Document After a Word Mail Merge

Olivia MillerOlivia Miller Nov 14, 2026 869 views

Question details

The user needs to keep a reference to the document created by a Word mail merge for subsequent processing.

Capture a Merged Document After a Word Mail Merge
Product
Microsoft Word
Device & OS
not provided
Scenario
A VBA procedure merges a template into a new document, then closes the template and performs conditional operations on the output.
Observed behavior
Closing the template can activate a different open document, so the active document or a generated document name may not identify the merged output.
Before you start

Open the Word VBA editor and locate the procedure that executes the mail merge. Identify the variable that refers to the original template and the Word application instance used by the procedure.

Solution 1Recommended

Store the New Mail Merge Document in a VBA Variable

Use a document reference captured immediately after the merge to keep processing the correct output, even if another document becomes active.

The template variable still refers to the original document after the merge. Capture the new active document before closing the template or activating another window.

1
Open the merge procedure

In Word, open the VBA editor and find the code that runs the mail merge. In the following example, wddoc refers to the template and objapp refers to its Word application instance.

2
Execute and capture the output

Declare wdActiveDoc as a Word.Document, set the destination to a new document, and capture it immediately: Dim wdActiveDoc As Word.Document wddoc.MailMerge.Destination = wdSendToNewDocument wddoc.MailMerge.Execute Set wdActiveDoc = objapp.ActiveDocument

3
Close the template when appropriate

After capturing the output, close wddoc if your procedure no longer needs it. For example, use wddoc.Close SaveChanges:=wdDoNotSaveChanges only if you intend to discard any unsaved template changes.

4
Process the captured document

Use wdActiveDoc for subsequent operations instead of names such as Document3 or Form Letters3. If you need its window to be active for an interactive operation, run wdActiveDoc.Activate first.

Store the New Mail Merge Document in a VBA Variable
Capture the reference immediately: ActiveDocument depends on which Word document is active. Assign it immediately after the merge, before code or user actions can change the active window.
Free Microsoft Office alternative

Edit Merged Documents with WPS Writer

WPS Office is a free, lightweight Office alternative with a familiar interface. Open compatible Word documents in WPS Writer for a straightforward move between office suites; it does not fix Microsoft Word VBA behavior.

Edit and review mail merge output documents in WPS Writer.Works with Microsoft Word formats, including DOC and DOCX.Use a familiar document-editing interface.Get a free, lightweight office suite for everyday work.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Word activate a different document when I close the template?

Word may return to another recently used document when the template closes. Capture objapp.ActiveDocument immediately after the merge and use that stored reference instead of relying on which window is active later.

Does the template variable point to the merged document after execution?

No. The variable used for the original template still points to that document. Assign the merged output to a separate Word.Document variable immediately after MailMerge.Execute.

Can I use the generated document name to find the merge output?

Names such as Document3 or Form Letters3 can vary depending on the documents already open. A document object reference is more reliable than a generated name or document number.

How can I make the merged document active again?

After storing it in a variable such as wdActiveDoc, run wdActiveDoc.Activate. For operations that support a document reference, use wdActiveDoc directly instead of depending on the active window.