Displaying a User Form

To load a UserForm called UserForm1 into memory, without making it visible, you use the Load statement:

Load UserForm1

You can remove UserForm1 from memory using the Unload statement:

Unload UserForm1

To make UserForm1 visible, use the Show method of the UserForm object:


If you show a UserForm that has not been loaded, it will be automatically loaded. You can use the Hide method to remove a UserForm from the screen without removing it from memory:


Figure 13-1 shows a simple UserForm in action that will be developed over the course of this chapter. It has been designed to allow you to see the current values in cells B2:B6 and to make changes to those values. It is linked directly to the cells in the worksheet, which makes it very easy to set up with a minimum of VBA code.

Excel 2010 Create Vba Userform
Figure 13-1

The ActiveX command button in the worksheet, with the caption Show Dialog, contains the following event procedure:

Private Sub cmdShowUserForm_Click()

frmPersonal.Show End Sub

The UserForm is modal by default. This means that the UserForm retains the focus until it is unloaded or hidden. The user cannot activate the worksheet or click Ribbon buttons until the UserForm is closed.

Modeless UserForms, which do allow the user to perform other tasks while they are visible, are discussed later in this chapter.

0 0


Post a comment