Skip to main content

UserForm.Show method

Displays a UserForm object.

Syntax

object ].Show modal

The Show method syntax has these parts:

Part Description
object Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the UserForm associated with the active UserForm module is assumed to be object.
modal Optional. Variant value that determines if the UserForm is modal or modeless.

Settings

The settings for modal are:

Constant Value Description
vbModal 1 UserForm is modal. Default.
vbModeless 0 UserForm is modeless.

Remarks

If the specified object isn't loaded when the Show method is invoked, Visual Basic automatically loads it.

When a UserForm is modeless, subsequent code is executed as it is encountered. Modeless forms don't appear in the task bar and are not in the window tab order.

When a UserForm is modal, the user must respond before using any other part of the application. No subsequent code is executed until the UserForm is hidden or unloaded. Although other forms in the application are disabled when a UserForm is displayed, other applications are not.

Example

The following example assumes two UserForms in a program. In UserForm1's Initialize event, UserForm2 is loaded and shown. When the user clicks UserForm2, it is hidden and UserForm1 appears. When UserForm1 is clicked, UserForm2 is shown again.

' This is the Initialize event procedure for UserForm1
Private Sub UserForm_Initialize()
    Load UserForm2
    UserForm2.Show
End Sub
' This is the Click event for UserForm2
Private Sub UserForm_Click()
    UserForm2.Hide
End Sub

' This is the click event for UserForm1
Private Sub UserForm_Click()
    UserForm2.Show
End Sub

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>