Permission & Access Issues

How to Restrict Word Documents to Form Filling Using VBA

Tauseeq MagsiTauseeq Magsi Oct 13, 2026 870 views

Question details

The user needs to use a VBA script to restrict editing in a Word document so that users can only fill out designated form fields, ensuring existing revision protections are handled without errors.

How to Restrict Word Documents to Form Filling Using VBA
Product
Word
Device & OS
not provided
Scenario
Automating document protection settings for multiple files via macros to ensure uniform data entry without allowing structural edits.
Observed behavior
The goal is to programmatically unprotect a document from previous restrictions (like revision tracking) and correctly re-protect it specifically for form filling using VBA.
Before you start

Before running the VBA script, ensure you have the correct password for any existing document protection, and save a backup copy of your Word document to prevent accidental data loss during macro testing.

Solution 1Recommended

Apply Form-Filling Protection Using VBA

Use a VBA macro to systematically unprotect the document from previous restrictions and apply the wdAllowOnlyFormFields protection type.

When processing multiple documents, a file might already have revision protection or other restrictions enabled. It is best practice to first remove any existing protection using the Unprotect method before applying the new restriction to avoid runtime errors.

1
Open the VBA Editor

Open your Word document and press 'Alt + F11' to launch the Visual Basic for Applications (VBA) editor.

2
Insert a New Module

In the left-hand Project Explorer pane, right-click your document name, select 'Insert', and click on 'Module'.

3
Write the Protection Code

Enter the VBA script. Use 'oDoc.Unprotect Password:="YourPassword"' to clear existing restrictions, followed by 'oDoc.Protect Type:=wdAllowOnlyFormFields, Password:="YourPassword"' to restrict editing to forms.

4
Run the Macro

Press 'F5' or click the 'Run' button in the toolbar to execute the script and update the document's protection settings.

Password Security in VBA: Always handle passwords securely. Hardcoding passwords directly into your VBA scripts can expose them to unauthorized users who have access to view the macro code.
WPS Writer Solution

Easily Restrict Documents to Form Filling in WPS Writer

While VBA macros are great for bulk processing, WPS Writer allows you to easily restrict editing and allow only form filling through its user-friendly interface, requiring absolutely no code.

  1. 1. Open Document: Launch WPS Writer and open the document containing your form fields.
  2. 2. Access Review Tab: Navigate to the 'Review' tab located on the top ribbon menu.
  3. 3. Open Restrict Editing: Click on the 'Restrict Editing' button to open the protection options pane on the right.
  4. 4. Set Editing Restrictions: Check the box for 'Allow only this type of editing in the document' and select 'Filling in forms' from the dropdown menu.
  5. 5. Enforce Protection: Click 'Start enforcing protection', enter a secure password, and click 'OK'.
Fully compatible with Microsoft Word document formats (.docx)Intuitive graphical interface for restricting document permissionsRobust form control tools for creating fillable templates easily
QA img-9

Frequently Asked Questions

Can I unprotect a Word document in VBA without the original password?

No, Word requires the correct password to unprotect a document programmatically using the Unprotect method. If the document is password-protected and the script does not provide the correct password, the macro will throw an error.

What exactly does wdAllowOnlyFormFields do in VBA?

The wdAllowOnlyFormFields is a built-in VBA enumeration constant. When applied via the Protect method, it locks the structural content of the document and restricts user interaction to only modifying form controls like text fields, checkboxes, and dropdown lists.

Why do I get a runtime error when applying form field protection via VBA?

This typically occurs if the document is already protected with another method (such as tracked changes or read-only). You must always call the Unprotect method to clear existing restrictions before applying a new ProtectionType like wdAllowOnlyFormFields.

Do I need to check if the document is protected before calling Unprotect?

Yes, it is highly recommended. You can check the ProtectionType property of the document first. If ProtectionType is not wdNoProtection, then execute the Unprotect command to prevent errors.