Microsoft Office Tutorials and References
In Depth Information
Displaying a UserForm
Testing a UserForm
You’ll usually want to test your UserForm while you’re developing it. You can test a UserForm in
three ways without actually calling it from a VBA procedure:
Choose the Run➜Run Sub/UserForm command.
Press F5.
Click the Run Sub/UserForm button on the Standard toolbar.
These three techniques all trigger the UserForm’s Initialize event. When a dialog box is
displayed in this test mode, you can try out the tab order and the accelerator keys.
Setting hot keys
You can assign an accelerator key, or hot key, to most dialog box controls. An accelerator key
allows the user to access the control by pressing Alt+ the hot key. Use the Accelerator
property in the Properties window for this purpose.
Some controls, such as a TextBox , don’t have an Accelerator property because they
don’t display a caption. You still can allow direct keyboard access to these controls by
using a Label control. Assign an accelerator key to the Label and put it before the
TextBox in the tab order.
Displaying a UserForm
To display a UserForm from VBA, you create a procedure that uses the Show method of the
UserForm object. If your UserForm is named UserForm1 , the following procedure displays the
dialog box on that form:
Sub ShowForm()
UserForm1.Show
End Sub
This procedure must be located in a standard VBA module and not in the code module for the
UserForm.
When the UserForm is displayed, it remains visible on-screen until it’s dismissed. Usually, you’ll
add a CommandButton control to the UserForm that executes a procedure that dismisses the
UserForm. The procedure can either unload the UserForm (with the Unload command) or hide
the UserForm (with the Hide method of the UserForm object). This concept will become
clearer as you work through various examples in this and subsequent chapters.
 
Search JabSto ::




Custom Search