Pages

How to add labels to VBA Userforms

Labels are a very important control type available in VBA. Can’t imagine a VBA form which doesn’t have a label. Because labels are essential when designing user interfaces. So today let’s look at how to add labels to a VBA userforms.

Suppose that we need to create a userform with the following fields.

Order Number
Project Number
Starting Date
Attending Surveyor
Date of Pressure Test
Comments

So this is our VBA userform.

VBA userform

Now let’s see how to add our first label to this form. First click somewhere on the userform. You will see a Toolbox appear like this.

Toolbox

If your Toolbox is missing then follow the below steps.

Click on the “View” menu.

Click on view menu

Then select Toolbox.

Select toolbox

Now we have the Toolbox. Next we can insert a label to our VBA form. To do that, select the label icon on the Toolbox

Select label icon

Now left click on the form where you want to create the label and drag the mouse to create a small rectangle while pressing down the left mouse button.

Left click and drag to form a rectangle

Now release the left mouse button.

Insert label

We have inserted a label to our form. Next we need to add 5 more labels to the form. There are two ways to add those 5 labels. You can either follow the same steps again for five times or create five copies of this inserted label. If you want to create a copy, then right click on the inserted label. And select “Copy”.

Copy label

Next right click on the form and select “Paste”

Select paste

Also you can use shortcut keys Ctrl + c to copy and Ctrl + v to paste instead of using the mouse. Usually, you may want to move the labels inside the form to format it correctly. If you want to move the label then left click on the label and drag it to the place where you want while clicking down the left mouse button.

VBA form with 6 labels

So now we have added six labels to the form. Next we need to change the text of each label. To do that we need to go to the properties window. Select the first label and go to the caption field of the properties window.

Caption field of the properties window

Now replace the text “Label1” with the first field “Order Number”.

Change of the caption of the first label

We can follow the same process for all the labels. So the final result would look like this.

Change caption of all the labels

Select the form and press the F5 key on the keyboard. This is how it will look like in the running mode.

Form’s appearance in the running status