Fix Word VBA Errors When Deleting Sections in Protected Forms
Question details
Fix VBA errors when a Word macro deletes sections from a protected form and then attempts to reprotect it.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A form field exit macro deletes sections and then restores form protection.
- Observed behavior
- Word can return error 5224 when protection is applied with the selection in an invalid location. A subsequent attempt to reprotect may return error 4641, indicating that the ToolsProtectDocument statement is disabled.
In Word, open the form's VBA project and identify the exit macro, the sections it deletes, and a form field that remains afterward. Check whether the document uses a protection password and whether the Developer tab is available.
Select a valid form field before reprotecting the document
Use this approach when error 5224 occurs after section deletion leaves the selection in an invalid location.
In Word, open Developer > Visual Basic and locate the macro assigned to the form field's exit event.
Find a form field that remains after the macro deletes the sections, preferably the next field in the form. Confirm its bookmark name in the form field's properties.
After the section-deletion code and before the protection command, add: ActiveDocument.FormFields("Text1").Select. Replace Text1 with the name of the surviving field.
While the document is unprotected, apply protection after selecting the field, for example: ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True. Supply the password if the form's protection requires one.
Return to the document, use the form field to run its exit macro, and confirm that the sections are deleted and form protection is restored.

Troubleshoot error 4641 when restoring form protection
Use this check if Word reports that the ToolsProtectDocument statement is disabled.
Edit Word Documents with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. Its format compatibility helps you move everyday documents to WPS, though it does not fix Microsoft Word VBA errors.

Frequently Asked Questions
Why does error 5224 occur after my macro deletes sections?
Deleting sections can leave the selection in a location that is invalid for the Protect command. After deletion, select a form field that still exists before calling ActiveDocument.Protect.
How do I find the name to use in FormFields?
In Word, open the form field's properties and check its bookmark name. Use that name in ActiveDocument.FormFields("FieldName").Select, and make sure the field is not deleted by the macro.
Does a second dropdown need different exit macro syntax?
Not necessarily. Check that its exit macro is assigned in the dropdown's form field properties, then use Developer > Visual Basic to verify that the macro reaches its code and selects a valid field before reprotection.
What should I check if Word reports error 4641?
Check ActiveDocument.ProtectionType and the status under Developer > Restrict Editing. If the macro uses ToolsProtectDocument, try ActiveDocument.Protect after selecting a surviving field and confirming that the document is unprotected.
Will WPS Office fix my Word VBA macro?
No. WPS Office can open and edit compatible Word documents, but it does not fix errors in Microsoft Word. Test the macro in Word and verify any macro compatibility before migrating the form.




