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.
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.
If your Toolbox is missing then follow the below steps.
Click on the “View” menu.
Then 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
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.
Now release the left mouse button.
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”.
Next right click on the form and 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.
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.
Now replace the text “Label1” with the first field “Order Number”.
We can follow the same process for all the labels. So the final result would look like this.
Select the form and press the F5 key on the keyboard. This is how it will look like in the running mode.