Showing and Hiding Forms

To display a form from the Excel application, call the Show() method of the UserForm object in a procedure that can be triggered from Excel (a public procedure in a standard module or an event procedure from an object module). The basic syntax follows:

UserFormName.Show [Modal]

To Load a form into system memory without displaying it, call VBA's Load() method.

Load UserFormName

The UserForm object and all of its components can be accessed programmatically after loading it into memory. Note that the Show() method will also load a form if it has not been previously loaded into memory.

For example, the following code displays a UserForm object named frmMessage when the Click() event procedure of a Command Button control named cmdShowForm is triggered. The Command Button control can be placed on a worksheet or another form.

Private Sub cmdShowForm_Click()

frmMessage.Show End Sub

To hide a form from the user but retain programmatic control, call the Hide() method of the UserForm object.

UserFormName.Hide

The Hide() method does not remove the UserForm object from system memory, thus the form and its components can still be accessed programmatically. To remove a form from system memory, call VBA's UnLoad() method.

UnLoad UserFormName

Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook


Post a comment