How to Use Word Radio Buttons and VBA to Calculate Table Totals
Question details
The user needs to calculate and display table totals dynamically using radio buttons and VBA code, but the calculation is failing due to missing macros.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Attempting to create a dynamic Word form where selecting different radio buttons triggers a VBA macro to calculate and update totals in a table.
- Observed behavior
- The automatic calculation does not work because the underlying VBA procedures, form controls, or table cell references are missing or broken.
Before inspecting or editing VBA macros, verify that the document is from a trusted source to avoid security risks. Ensure that the Developer tab is enabled in your ribbon settings so you can access the necessary macro and form control tools.
Inspect and Restore Missing VBA Macros and Form Controls
Identify missing VBA procedures and form controls to restore the calculation functionality in your document.
When calculations fail in a macro-enabled document, the issue is typically caused by missing VBA code, broken references to table cells, or disconnected form controls. You must inspect the document's Visual Basic backend to diagnose the exact missing component.
Navigate to the Developer tab on your ribbon and click 'Visual Basic' to open the VBA editor.
In the Project Explorer pane on the left, expand 'ThisDocument' and the 'Modules' folder to search for the calculation macro. If the code area is blank, the macro has been lost or deleted.
Return to the document, click 'Design Mode' on the Developer tab, right-click your radio button, and select 'Properties'. Ensure the (Name) field matches the exact object name referenced in your VBA code.
Review the VBA code to ensure it is targeting the correct table and cells (e.g., ActiveDocument.Tables(1).Cell(Row, Column)). Adjust the indices if rows or columns have been added or removed.

Create a New VBA Macro for Table Totals
If the original code is missing, write a new VBA subroutine triggered by the radio button to sum the table values.
Calculate Totals Easily with WPS Office
WPS Office provides excellent support for form controls and VBA macros in its advanced editions, allowing you to easily automate document calculations and troubleshoot missing code.
- 1. Enable the Developer Tab: Open your document in WPS Writer, go to the settings, and enable the Developer tab to access macro tools.
- 2. Insert Form Controls: Click 'Design Mode' in the Developer tab and insert a Radio Button from the controls menu.
- 3. Edit VBA Code: Click 'Visual Basic' or 'Macros' to enter or fix your table calculation script.
- 4. Test the Calculation: Exit Design Mode and select the radio button to verify that the table totals calculate automatically.

Frequently Asked Questions
Why are my Word macros disabled by default?
For security reasons, Office programs disable macros by default to protect your computer from potentially malicious code. You must manually enable them in the Trust Center settings or click 'Enable Content' when opening a trusted document.
How do I reference a specific table cell in Word VBA?
You can reference a cell using the syntax ActiveDocument.Tables(table_index).Cell(row, column).Range.Text. Note that Word includes an end-of-cell marker in the text, which you may need to strip out before converting it to a number for calculation.
Why doesn't my radio button trigger the calculation macro?
Ensure that you are using an ActiveX radio button rather than a standard content control if you want it to trigger a VBA event like OptionButton_Click(). Additionally, verify that 'Design Mode' is turned off on the Developer tab, as macros will not run while Design Mode is active.




