How to Call Userform Initialize in VBA

Iqra Hasnain Feb 15, 2024
How to Call Userform Initialize in VBA

In this article, we will introduce user form in VBA. We will also explore an example to learn how to initialize a form in VBA functions.

Call Userform Initialize in VBA

While working with excel, we always have wondered how we can make a form with the help of which we can easily allow users to make a user data entry more controllable and easier to use.

We will go through an example in which we will create a simple form in VBA by following the steps.

  • Go to the Developers tab and click on Visual Basic, as shown in the picture below.

    call userform initialize in vba - click visual basic

  • Click on Insert Userform, then click on Userform, as shown in the picture below.

    call userform initialize in vba - click userform

  • It will create a new form, We can easily add labels and input fields by clicking on the buttons, and we will create a sample design as shown below.

    call userform initialize in vba - click on the button to add input fields and labels

    The design of the form is shown below.

    call userform initialize in vba - form

Now, let’s create a sub-function and try to call this user form in it. But, first, we will rename the name property of the user form we just created in VBA to something we can remember to call, like testForm, as shown below.

call userform initialize in vba - update form name

Then, we will create a new sub-function, as shown below.

#VBA
Sub showForm()
end sub

Next, we will define a new form using the name of the form and use the property of show to display it, as shown below.

#VBA
Sub showForm()
Dim userForm As New testForm
userForm.show
end sub

Now, we will run the code as shown below.

call userform initialize in vba - show form using function

The above example displays the form without any when we execute the functions. This way, we can show multiple or single forms to add values to the sheet.