Microsoft Office Tutorials and References
In Depth Information
Creating a UserForm: An Example
UserForms also have a Hide method. When you invoke this method, the UserForm disappears,
but it remains loaded in memory, so your code can still access the various properties of the
controls. Here’s an example of a statement that hides a UserForm:
Or, if the code is in the code module for the UserForm, you can use the following:
If for some reason you’d like your UserForm to disappear immediately while its macro is
executing, use the Hide method at the top of the procedure. For example, in the following procedure,
the UserForm disappears immediately when CommandButton1 is clicked. The last statement in
the procedure unloads the UserForm.
Private Sub CommandButton1_Click()
Application.ScreenUpdating = True
For r = 1 To 10000
Cells(r, 1) = r
Next r
Unload Me
End Sub
In this example, I set ScreenUpdating to True to force Excel to hide the UserForm
completely. Without that statement, the UserForm may actually remain visible.
In Chapter 15, I describe how to display a progress indicator, which takes advantage of
the fact that a UserForm remains visible while the macro executes.
Creating a UserForm: An Example
If you’ve never created a UserForm, you might want to walk through the example in this section.
The example includes step-by-step instructions for creating a simple dialog box and developing a
VBA procedure to support the dialog box.
This example uses a UserForm to obtain two pieces of information: a person’s name and sex. The
dialog box uses a TextBox control to get the name and three OptionButtons to get the sex
(Male, Female, or Unknown). The information collected in the dialog box is then sent to the next
blank row in a worksheet.
Search JabSto ::

Custom Search