VBA & Macro Problems

Fix Word VBA Clearing Legacy Form Fields When Protecting a Document

Rana GarciaRana Garcia Nov 22, 2026 870 views

Question details

Update document-variable fields and protect a Word document without clearing legacy form field values.

Fix Word VBA Clearing Legacy Form Fields When Protecting a Document
Product
Microsoft Word VBA
Device & OS
not provided
Scenario
A Word macro updates fields and then protects a document containing legacy form fields.
Observed behavior
Updating the entire document field collection can erase or alter legacy form field values.
Before you start

Identify the macro that calls ActiveDocument.Fields.Update and confirm which fields are DOCVARIABLE fields. If the document is already protected, use Review > Restrict Editing > Stop Protection and enter the password if prompted.

Solution 1Recommended

Update DOCVARIABLE Fields Individually Before Protecting the Document

Use this approach to avoid updating legacy form fields as part of a document-wide field update.

1
Open the macro

In Word, open Developer > Visual Basic and locate the macro that updates and protects the document.

2
Replace the field update

Remove ActiveDocument.Fields.Update. In its place, loop through the fields and update only document-variable fields: Dim fld As Field For Each fld In ActiveDocument.Fields If fld.Type = wdFieldDocVariable Then fld.Update Next fld

3
Protect the document

After the loop, add ActiveDocument.Protect Type:=wdAllowOnlyReading to apply read-only protection. Run this statement only when the document is not already protected.

4
Test the macro

Return to Word, enter sample values in the legacy form fields, and run the macro from Developer > Macros. Check that the values remain intact and the DOCVARIABLE fields show the expected results.

Update DOCVARIABLE Fields Individually Before Protecting the Document
Choose the protection mode for your form: wdAllowOnlyReading restricts editing; it is not the same as protection for filling in forms. If users need to fill legacy fields after protection, test wdAllowOnlyFormFields instead. Update fields in headers, footers, or other story ranges separately if needed.
Free Microsoft Office alternative

Edit Word Documents with WPS Writer

WPS Writer is a free, lightweight Office alternative with a familiar interface and support for Word formats, making it easy to move everyday document editing to WPS. It does not fix Microsoft Word VBA protection behavior.

Open and edit Microsoft Word DOC and DOCX documentsUse a familiar interface for everyday document editingWork with form documents in a lightweight Office suiteMove existing Word files into WPS without starting over
microsoft office alternative - wps office

Frequently Asked Questions

Why does Fields.Update affect my legacy form fields?

Legacy form fields are included in Word's field collection, so ActiveDocument.Fields.Update can update them along with other fields and alter their values. Update only the field types you need instead.

How do I update only DOCVARIABLE fields in Word VBA?

In Developer > Visual Basic, loop through ActiveDocument.Fields and call fld.Update only when fld.Type equals wdFieldDocVariable.

Can users fill in legacy fields under read-only protection?

Read-only protection is intended to restrict editing. If users need to fill in legacy form fields, test wdAllowOnlyFormFields instead of wdAllowOnlyReading.

Will ActiveDocument.Fields include fields in headers and footers?

The main document field collection does not cover every story range. If DOCVARIABLE fields appear in headers or footers, update those story ranges separately.