Protect a Word Mail Merge Document with VBA
Question details
The user wants to protect a Word document after an automated mail merge so staff cannot modify its contents.

- 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.
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.
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.
In desktop Word, open the macro-enabled document and select Developer > Visual Basic. Find the procedure that runs the mail merge.
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.
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.
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.

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.

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.




