How to Calculate the Percentage of Checked Word Checkboxes with VBA
Question details
The user needs to calculate and display the percentage of selected checkboxes in a Word quality-control checklist using a VBA macro.

- Product
- Word Processing (Microsoft Word / WPS Writer)
- Device & OS
- not provided
- Scenario
- Creating a dynamic quality-control checklist document utilizing multiple simple legacy form-control checkboxes that must output a completion metric.
- Observed behavior
- The user requires an automated method via VBA where exiting a selected checkbox updates a calculated text form field with the current completion percentage.
Ensure that the Developer tab is enabled in your word processor's ribbon, as you will need access to legacy form fields and the VBA editor to implement and assign the macro.
Use a VBA Macro for Legacy Form Field Checkboxes
Create a VBA macro that counts all legacy form fields, checks their true/false status, calculates the percentage, and outputs it to a designated text field upon exiting a checkbox.
This method requires your document to use legacy form controls (not ActiveX or Content Controls). You will assign this macro to run automatically whenever a user exits a checkbox, providing real-time percentage updates.
Insert your legacy checkbox form fields into the document layout. Then, insert a Legacy Text Form Field where you want the percentage to appear. Double-click this text field and set its Bookmark name to 'PercentageChecked'.
Press Alt + F11 to open the VBA Editor. Insert a new module by clicking Insert > Module from the top menu.
Write a script that loops through 'ActiveDocument.FormFields'. Count the total number of CheckBox types and track how many have a '.CheckBox.Value' of True. Calculate the percentage (Checked / Total * 100) and assign the formatted result to 'ActiveDocument.FormFields("PercentageChecked").Result'.
Return to your document view. Double-click each checkbox to open its properties dialog, locate the 'Run macro on exit' dropdown, and select the macro you just created. Finally, protect the document for 'Filling in forms' to activate the logic.

Create Automated Checklists Easily with WPS Writer
WPS Writer provides robust, built-in support for legacy form fields and VBA macros, allowing you to seamlessly construct automated quality-control checklists that calculate dynamic percentages in real-time.
- 1. Enable the Developer Tab: Open WPS Writer, go to Options > Customize Ribbon, and check the 'Developer' box to reveal form controls.
- 2. Insert Checkboxes: Navigate to the Developer tab, select Legacy Forms, and insert Check Box Form Fields into your checklist.
- 3. Add the VBA Script: Click 'Macros' in the Developer tab, create a new macro for your calculation, and paste your VBA percentage logic.
- 4. Apply Exit Macro: Double-click your checkboxes and configure the 'Run macro on exit' option to execute your script automatically.

Frequently Asked Questions
Why isn't my checklist percentage updating automatically?
The macro must be strictly assigned to the 'Exit' event of each checkbox. Double-click the checkbox to open its properties dialog and ensure the 'Run macro on exit' dropdown is set to your calculation macro.
Does this calculation macro work with Content Control checkboxes?
No, this specific VBA logic relies on iterating through Legacy Form Fields. Content controls require a different VBA approach using the Document_ContentControlOnExit event instead.
How do I ensure users can check the boxes without altering the text?
You need to protect the document. Go to the Developer tab, select Restrict Editing, check the editing restrictions box, and set the dropdown to 'Filling in forms'.




