Skip to main content

Initialize event

Table of contents
  1. Syntax
  2. Remarks
  3. Example

Occurs after an object is loaded, but before it's shown.


Private Sub object_Initialize( )

The object placeholder represents an object expression that evaluates to an object in the Applies To list.


The Initialize event is typically used to prepare an application or UserForm for use.Variables are assigned initial values, and controls may be moved or resized to accommodate initialization data.


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
End Sub
' This is the Click event of UserForm2
Private Sub UserForm_Click()
End Sub

' This is the click event for UserForm1
Private Sub UserForm_Click()
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>