Update Fields in a Protected Word Document with VBA
Question details
Update calculated fields, such as table totals, while a Word document is protected.
- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A protected form contains values and calculated fields that need to be refreshed after editing.
- Observed behavior
- Fields that update with F9 in an unprotected document may not update after protection is enabled.
Check whether the form uses legacy form fields or content controls, and confirm that you know the protection password if one is set. If you use a macro, save the document as a macro-enabled Word document (.docm) and allow macros only if you trust the document.
Update protected Word fields with a VBA macro
Use this approach for content controls when fields need to be updated and you can remove and reapply the document's protection.
The macro records the protection type, removes protection, updates fields in the main document, and reapplies the protection type with NoReset set to True. It also attempts to restore protection if the field update fails.
The macro does not update fields in every document story, such as headers and footers, and it may not restore every protection option or editing exception. Test it with the document's protection settings before relying on it.
In Word, open the document and select Developer > Visual Basic. If the Developer tab is hidden, enable it in Word's ribbon customization settings.
In the VBA editor, select Insert > Module and paste the following code into the module: Sub Recalc() Const Pwd As String = "Password" Dim pState As WdProtectionType Dim wasUnprotected As Boolean Dim failed As Boolean Dim msg As String Dim oldScreenUpdating As Boolean On Error GoTo Failed oldScreenUpdating = Application.ScreenUpdating pState = ActiveDocument.ProtectionType Application.ScreenUpdating = False If pState <> wdNoProtection Then ActiveDocument.Unprotect Password:=Pwd wasUnprotected = True End If ActiveDocument.Fields.Update GoTo Cleanup Failed: failed = True msg = Err.Description Resume Cleanup Cleanup: On Error Resume Next If wasUnprotected Then Err.Clear ActiveDocument.Protect Type:=pState, NoReset:=True, Password:=Pwd If Err.Number <> 0 Then failed = True msg = msg & vbCrLf & "Could not restore protection: " & Err.Description End If End If Application.ScreenUpdating = oldScreenUpdating On Error GoTo 0 If failed Then MsgBox msg, vbExclamation End Sub
In the Pwd line, replace Password with the document's protection password. If there is no password, use an empty string: Const Pwd As String = "".
Return to Word, select Developer > Macros, choose Recalc, and select Run. Check the calculated fields and use Review > Restrict Editing to verify that protection is still enforced.
Calculate fields on exit in a protected legacy form
Use this option instead of a macro when the document uses legacy form fields with Filling in Forms protection.
Edit Word-Compatible Documents with WPS Writer
WPS Writer is a free, lightweight Office alternative with a familiar interface for opening and editing Word documents. Its format compatibility helps make moving everyday documents from Microsoft Office straightforward, but it does not fix Word's protection or VBA behavior.

Frequently Asked Questions
Why doesn't F9 update my fields in a protected document?
Word's editing protection can prevent a field from updating in the usual way. For legacy form fields, try Calculate on exit in the field's Properties; for other forms, temporarily removing protection with a macro may help.
Can I update a legacy form without a macro?
Yes. Open the legacy field's Properties on the Developer tab, enable Calculate on exit, and enforce Filling in forms protection through Review > Restrict Editing.
What does NoReset do when the macro reapplies protection?
NoReset:=True tells Word not to reset form fields when protection is applied. It does not guarantee that every protection setting or editing exception is restored.
Will the macro update fields in headers and footers?
No. ActiveDocument.Fields.Update updates fields in the main document story. Fields in headers, footers, and other stories require additional code.
What if I don't know the document protection password?
Ask the document owner for the password or an editable copy. The macro cannot remove password protection without the correct password.




