Using Events with ActiveX Controls
Word documents can contain ActiveX controls. Use the Control Toolbox to insert ActiveX controls such as command buttons, check boxes, and list boxes. Use the following steps to add an ActiveX check box control with a LostFocus event.
On the Developer tab, click the Check Box control. A check box control is inserted in the active document.
Right-click the check box control and click View Code. Word switches to the Visual Basic Editor and displays the ThisDocument class module with the check box selected in the Object drop-down list box.
Select the LostFocus event from the Procedure drop-down list box. An empty procedure is added to the class module.
Add the Visual Basic instructions you want to run when the event occurs.
The following example shows a LostFocus event procedure that runs when the focus is moved away from CheckBox1. The macro displays the state of CheckBox1 using the Value property (True for selected and False for clear).
Private Sub CheckBox1_LostFocus() MsgBox CheckBox1.Value End Sub
To see your event procedure run, switch back to Word with the document that includes the check box displayed. Click the Exit Design Mode button on the Control Toolbox. Select or clear the check box and then click another element in the document. The check box control loses the focus and your LostFocus procedure runs; a message box is displayed with either "True" or "False." Word implements the LostFocus and GotFocus events for ActiveX controls in a Word document. The other events listed in the Procedure drop-down list box in are documented in Microsoft Forms Help.
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.