Microsoft Office Tutorials and References
In Depth Information
Displaying a UserForm
Displaying a modeless UserForm
By default, UserForms are displayed modally. This means that the UserForm must be dismissed
before the user can do anything in the worksheet. You can also display a modeless UserForm.
When a modeless UserForm is displayed, the user can continue working in Excel, and the
UserForm remains visible. To display a modeless UserForm, use the following syntax:
Displaying a UserForm based on a variable
In some cases, you may have several UserForms, and your code makes a decision regarding
which of them to display. If the name of the UserForm is stored as a string variable, you can use
the Add method to add the UserForm to the UserForms collection and then use the Show
method of the UserForms collection. Here’s an example that assigns the name of a UserForm to
the MyForm variable and then displays the UserForm:
MyForm = “UserForm1”
Loading a UserForm
VBA also has a Load statement. Loading a UserForm loads it into memory, but it’s not visible
until you use the Show method. To load a UserForm, use a statement like this:
If you have a complex UserForm, you might want to load it into memory before it’s needed so
that it will appear more quickly when you use the Show method. In the majority of situations,
however, you don’t need to use the Load statement.
About event-handler procedures
After the UserForm is displayed, the user interacts with it — selecting an item from a ListBox,
clicking a CommandButton, and so on. In official terminology, the user causes an event to occur.
For example, clicking a CommandButton causes the Click event for the CommandButton. You
need to write procedures that execute when these events occur. These procedures are
sometimes known as event-handler procedures.