How to Replace Word Form Checkboxes and Text Fields Using VBA
Question details
The user wants a VBA script to convert legacy Word form checkboxes into text representation (like [X] or [ ]) and legacy text fields into plain text results.

- Product
- Word Document
- Device & OS
- not provided
- Scenario
- Flattening a form document by converting interactive legacy form controls (checkboxes and text fields) into standard plain text.
- Observed behavior
- The user needs to replace checked checkboxes with '[X]', unchecked ones with '[ ]', and text fields with their corresponding result string.
Before running any VBA macro, ensure you have saved a backup copy of your document, as macro actions cannot typically be undone using the standard Undo feature.
Use VBA FormFields Collection to Replace Controls
Run a VBA macro that loops through the FormFields collection in reverse order, substituting each field with plain text counterparts.
When replacing fields with text using VBA, it is crucial to loop through the document from the end to the beginning (in reverse order). Modifying the document structure forward can mess up the collection index.
Note: If your document is protected for forms, you might normally need to use .Unprotect. However, if it is already unprotected, you can omit that line to avoid macro execution errors.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.
In the top menu, click 'Insert' and then select 'Module' to create a blank script window.
Write a For loop that iterates backwards through ActiveDocument.FormFields (e.g., For i = ActiveDocument.FormFields.Count To 1 Step -1).
Inside the loop, use an If statement to check the field type. For text fields, replace the field's range text with its .Result property. For checkboxes, evaluate .CheckBox.Value and insert '[X]' if True, or '[ ]' if False.
Close the VBA editor and press Alt + F8 to open the Macros dialog. Select your new macro and click 'Run' to flatten the document.

Handle Word Documents and Forms Seamlessly in WPS Office
WPS Office offers robust compatibility with Microsoft Word documents, including support for legacy form fields and VBA macros in its advanced versions. You can easily manage and flatten forms without extensive formatting issues.
- 1. Download and Install: Download WPS Office from the official website and complete the installation process.
- 2. Open Your Document: Launch WPS Writer and open your .doc or .docx file containing the legacy form fields.
- 3. Access the Developer Tools: Navigate to the Developer tab on the ribbon to manage Form Fields or launch the VBA Editor (requires the VBA module).
- 4. Run Document Macros: Execute your script to automate the replacement of checkboxes and text fields directly within WPS Writer.

Frequently Asked Questions
Why must I loop backwards through the FormFields collection in VBA?
When you replace a form field with plain text, the field is deleted from the collection. If you loop forward, the index numbers shift, causing the macro to skip fields or throw an error. Looping backwards from the last field to the first prevents this index shifting issue.
How do I check the state of a checkbox in VBA?
You can determine if a legacy checkbox form field is checked by reading its .CheckBox.Value property. It returns True if checked and False if it is unchecked.
What if my Word document is protected for filling in forms?
If the document is protected, you cannot modify its text via VBA directly. You must first unprotect it using ActiveDocument.Unprotect at the beginning of your script, and optionally reprotect it when finished.




