Permission & Access Issues

Protect a Word Mail Merge Document with VBA

Jason MillerJason Miller Nov 27, 2026 869 views

Question details

The user wants to protect a Word document after an automated mail merge so staff cannot modify its contents.

Protect a Word Mail Merge Document with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
A VBA macro performs a mail merge and should apply editing protection to the resulting document.
Observed behavior
The automation needs a document-protection command after the merge completes.
Before you start

Open the macro-enabled Word document that runs the merge and identify the line that executes it. Test changes on a copy and confirm that the merge creates a new document rather than sending output directly to a printer.

Solution 1Recommended

Add document protection after the mail merge

Use Word VBA to restrict editing of the newly merged document as soon as the merge finishes.

The wdAllowOnlyFormFields setting restricts editing to form fields; those fields remain editable. The command must target the merged output, not the original mail merge source document.

1
Open the macro

In desktop Word, open the macro-enabled document and select Developer > Visual Basic. Find the procedure that runs the mail merge.

2
Create a merged document

Ensure the macro sets the mail merge destination to wdSendToNewDocument before calling the merge's Execute method. A merge sent directly to a printer does not create a document for this command to protect.

3
Protect the output

Immediately after the merge executes, add: ActiveDocument.Protect Type:=wdAllowOnlyFormFields. Confirm that the newly merged output is the active document at that point; otherwise, use a document variable that refers to the output instead of ActiveDocument.

4
Run and verify

Run the macro on the test copy, then try editing ordinary text in the merged output. Check Review > Restrict Editing to confirm protection is active, and save the output using File > Save As.

Add document protection after the mail merge
Understand the protection limit: Without a password, users can stop editing protection. Even with a password, editing restrictions are not a substitute for encryption or access controls.
Free Microsoft Office alternative

Work with Word Documents in WPS Writer

WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Word format compatibility, making it easy to move everyday document work to WPS Writer. It does not fix or guarantee compatibility with Microsoft Word VBA automation.

Open and edit Microsoft Word DOC and DOCX filesReview and update mail merge documents in WPS WriterUse a familiar document-editing interfaceWork with a free, lightweight Office suite
microsoft office alternative - wps office

Frequently Asked Questions

Where should I put the protection command?

In Developer > Visual Basic, place the command immediately after the mail merge Execute call, when the merged output document is active.

Why is my original merge document protected instead of the output?

ActiveDocument refers to whichever document is active when the command runs. Set the merge destination to wdSendToNewDocument and verify that the output is active, or use a document variable that refers to the output.

Can staff still edit form fields?

Yes. The wdAllowOnlyFormFields protection type permits editing in form fields while restricting ordinary document edits.

Does this command prevent someone from removing protection?

Not by itself. Without a password, users can stop protection through Review > Restrict Editing. A password can restrict that action, but document protection is not encryption.