Microsoft Office Tutorials and References
In Depth Information
Closing a UserForm
with its own module. Accessing a UserForm’s module is easy: In the VBE, you can double-click the
UserForm itself in the design pane; or in the Project Explorer, you can right-click the UserForm
name and select View Code, as shown in Figure 18-17.
closing A usErforM
You have two ways to close a UserForm. One way is with the Unload method and the other way is
with the Hide method. Though both methods make the UserForm look as if it has gone away, they
each carry out different instructions. This can be a point of confusion for beginning programmers,
so it’s important to understand the distinction between Unload and Hide .
unloading a userform
When you unload a UserForm, the form closes and its entries are cleared from memory. In most
cases, that is what you would want — for the data that was entered to be recorded in some way,
or passed to Public variables, and then closed. The statement that unloads a UserForm is simply
Unload Me and it is commonly associated with a CommandButton for that purpose, such as the
Cancel button that was placed on this lesson’s example UserForm.
Suppose you want to unload the UserForm when the Cancel button is clicked. A quick and easy
way to do that is to double-click the CommandButton in the UserForm’s design, as shown in