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:
1.
Press Alt+F11 to activate the VBE.
2.
Make sure that the UserForm is displayed and double-click the CommandButton
captioned Close.
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.
3.
Modify the procedure as follows.
(This is the event handler for the CloseButton ’s Click event.)
Private Sub CloseButton_Click()
Unload UserForm1
End Sub
This procedure, which is executed when the user clicks the Close button, simply unloads
the UserForm.
4.
Press Shift+F7 to redisplay UserForm1 (or click the View Object icon at the top of the
Project Explorer window).
 
Search JabSto ::




Custom Search