logo
search
VBA & Macro Problems

How to Show a VBA Message Box for Two Checkboxes in Word

WPS Content ManagerWPS Content Manager Oct 1, 2026 870 views

Question details

The user needs to validate two checkboxes within a Word UserForm, displaying a warning message and disabling the execute button if neither checkbox is selected.

How to Show a VBA Message Box for Two Checkboxes in Word
Product
Microsoft Word
Device & OS
not provided
Scenario
Creating a UserForm dashboard in Word where users are required to select at least one of two specific checkboxes before they can proceed with document generation.
Observed behavior
The form must dynamically check the status of CheckBox15 and CheckBox16, warn the user via a MsgBox if both are blank, and prevent execution by toggling the CommandButton's enabled state.
Before you start

Ensure your Word document is saved as a Macro-Enabled Template (.dotm) while developing, and verify the exact names of your checkbox and button controls in the Visual Basic Editor (VBE) properties.

Solution 1Recommended

Validate Checkboxes and Control Button State Using VBA

Use a custom validation subroutine triggered by exit events to evaluate the status of both checkboxes and update the form accordingly.

To ensure users make a valid selection before proceeding, you can disable the Execute button by default and only enable it once the required checkboxes are clicked. Using the _Exit event allows the validation to happen as soon as the user finishes interacting with the checkbox.

1
Set Default Button State

Open the Visual Basic Editor (ALT + F11), select your CommandButton in the UserForm, and change its 'Enabled' property to 'False' in the Properties window.

2
Create the Validation Subroutine

In your UserForm's code, create a new sub named 'Validate'. Use an IF statement: 'If Not CheckBox15 And Not CheckBox16 Then'. Inside this condition, add 'MsgBox "Your warning text"' and 'CommandButton1.Enabled = False'. In the Else block, add 'CommandButton1.Enabled = True'.

3
Link Checkbox Exit Events

Generate the '_Exit' event for both CheckBox15 and CheckBox16 (e.g., 'Private Sub CheckBox15_Exit...'). Inside both of these event procedures, simply type 'Validate' to call your custom subroutine.

4
Add Failsafe Event Triggers

For added reliability, you can also call the 'Validate' subroutine in the '_Enter' event of the subsequent control the user is likely to click next.

Validate Checkboxes and Control Button State Using VBA
Real-time Validation: By attaching the validation to the Exit and Enter events, the form updates dynamically without requiring the user to click the submit button first.
Free Microsoft Office alternative

Try WPS Office for Seamless Document Management

If dealing with complex VBA macros and UserForms in Microsoft Word is slowing you down, consider switching to WPS Office. It provides a highly compatible, intuitive alternative for processing standard documents and forms without the steep learning curve.

  1. 1. Download WPS Office: Visit the official WPS website and install the free version of WPS Office.
  2. 2. Open Your Document: Launch WPS Writer and open your standard Word documents or templates instantly.
  3. 3. Edit and Save: Use the intuitive editing tools to finalize your work and save it in standard formats like .docx.
Seamless format compatibility with Microsoft Word (.docx, .doc, .dotm)Familiar interface for effortless document editing and form fillingLightweight design ensures fast loading and smooth performanceFree to use with comprehensive multi-platform support
microsoft office alternative - wps office

Frequently Asked Questions

Why does my UserForm dashboard reappear when I reopen the saved document?

If your document was saved as a macro-enabled file and uses an 'Auto_Open' macro, the form triggers on every open. Change the macro to 'Auto_New' so it only runs upon initial creation, and save the finalized output as a standard .docx file to remove the macros.

How do I trigger VBA code as soon as a user clicks a checkbox?

You can use the CheckBox's `_Exit` or `_Click` event in the Visual Basic Editor. The `_Exit` event is highly recommended for validation, as it executes the moment the user tabs away or clicks into another form control.

Can I disable a command button until certain conditions are met?

Yes. Set the CommandButton's 'Enabled' property to False by default. Once the user satisfies your required conditions (like checking a specific box), you can use VBA logic to set `CommandButton1.Enabled = True`.