Microsoft Office Tutorials and References
In Depth Information
Creating a UserForm: An Example
Figure 13-11: The CommandButton’s Click event procedure displays the UserForm.
Adding event-handler procedures
In this section, I explain how to write the procedures that will handle the events that occur when
the UserForm is displayed. To continue the example, do the following:
Press Alt+F11 to activate the VBE.
Make sure that the UserForm is displayed and double-click the CommandButton
This step activates the Code window for the UserForm and inserts an empty procedure
named CloseButton_Click . Notice that this procedure consists of the object’s name,
an underscore character, and the event that it handles.
Modify the procedure as follows.
(This is the event handler for the CloseButton ’s Click event.)
Private Sub CloseButton_Click()
This procedure, which is executed when the user clicks the Close button, simply unloads
Press Shift+F7 to redisplay UserForm1 (or click the View Object icon at the top of the
Project Explorer window).