Excel 2010 Bible

(National Geographic (Little) Kids) #1

Chapter 41: Creating UserForms


849


Creating an event-handler procedure

An event-handler procedure is executed when an event occurs. In this case, you need a procedure to
handle the Click event that’s generated when the user clicks the OK button.


  1. Activate the VB Editor. (Pressing Alt+F11 is the fastest way.)

  2. Activate the AboutBox UserForm by double-clicking its name in the Project
    window.

  3. Double-click the CommandButton control. The VB Editor activates the code module
    for the UserForm and inserts some boilerplate code, as shown in Figure 41.9.


FIGURE 41.9
The code module for the UserForm.


  1. Insert the following statement before the End Sub statement:


Unload AboutBox

This statement simply dismisses the UserForm by using the Unload statement. The complete
event-handler procedure is

Private Sub OKButton_Click()
Unload AboutBox
End Sub
Free download pdf