MultiPage Controls, Labels, Textboxes

Ongoing tutorial - First part is here: Part One

Open up the Excel VBA Editor. From the menus at the top, click on Insert. From the Insert menu, select User Form. With the form selected, locate the properties area on the left, and the Name property. (If you can't see any Properties, click View from the menu at the top of the Excel VBA Editor. From the View menu, select Properties Window. You can also press F4 on your keyboard as a shortcut.) Delete the default of UserForm1 and type PictureViewer. Change the following properties, as well:

Caption: Excel Picture Viewer
Height: 420
Width: 575


MultiPage Controls (Tabs)

The first object we want to add to the form is the MultiPage control. This will give us the tabs we need.

Make sure your form is selected and examine the toolbox. (If you can't see the toolbox, click View from the menu at the top of the Excel VBA Editor. From the View menu, select Toolbox.) Now click on the MultiPage control, which is circled in red in the image below:

The MultiPage control in the VBA toolbox

In the properties area for the MultiPage, change the Height to 378 and the Width to 558. Set the Top property to 10 and the Left property to 6.

By default, the MultiPage control has two pages. This is fine for us. To change the captions on the pages, click on the first one, which has the default name Page1. (Click exactly on the text Page1.) This will open up the properties for that page, rather than the MultiPage control as a whole. Locate the Caption property of Page1 and change it to View Photos. Now do the same for Page2. Click on the text Page 2 and change the Caption property to Add New Photo. The top of your form should now look like this:

Two tabs showing on a VBA MultiPage control

We can now add the controls to the MultiPage. The controls we want on the View Photos page are 7 Labels, 6 Textboxes, 1 ComboBox, 2 option buttons, 3 command buttons, and 1 picture frame. We'll add the labels first.

Adding Labels to a VBA User Form

Locate the label control in the toolbox, the one circled in the image below:

The label control in the toolbox

Draw out the first label anywhere on your form. Now set the following properties for the label:

Caption: File Name
Height: 18
Width: 54
Top: 72
Left: 24

Locate the Font property and click the grey button with the three dots in it:

The Font property

Clicking the button brings up the Font dialogue box:

The Font dialogue box

Set the font to Tahoma, Bold, 10 points. Then click OK.

Instead of drawing out the other 6 labels and setting the properties, you can copy and paste the first label. The pasted labels will then have all the same properties as the copied one (except for Top and Left).

Click on your first label to highlight it, then press CTRL + C to copy it. Press CTRL + V on your keyboard to paste it. The label should appear somewhere in the middle of the form. Drag it to the left somewhere, and then paste another 5 times. You'll then have 7 labels that say File Name.

To left-align all the labels, hold down the CTRL key on your keyboard. Keep it held down and left click each label in turn until they are all selected, as in the image below:

Seven labels selected at once

In the properties area, locate the Left property. Type in a value of 24 and press the enter key on your keyboard. All your labels will then left-align to the desired position.

Now set the following values for each label:


Caption: Date Taken
Width: 72
Top: 102


Caption: Information
Width: 66
Top: 132


Caption: Dimensions
Width: 66
Top: 162


Caption: Image Size
Width: 54
Top: 192


Caption: Camera
Width: 54
Top: 222


Caption: Flash
Width: 54
Top: 258


Adding Textboxes to a Form

Now that the labels are all done, add 6 Textboxes. For the first Textbox you can set the following properties:

Height: 20
Width: 120
Top: 66
Left: 96
Font: Tahoma, Bold, 10 points

Now copy and paste the first Textbox 5 times. Set the Left property for the other 6 textboxes by highlighting them all and typing 96 into the Left property area, just like you did for the labels.

Set the following individual properties for the Textboxes:


Name: txtFileName
Top: 66


Name: txtDate
Top: 102


Name: txtInfo
Top: 132


Name: txtDimensions
Top: 162


Name: txtSize
Top: 192


Name: txtCamera
Top: 222

Your form should now look like this:

User Form with labels and textboxes


In the next lesson below, you'll add the Option Buttons and the Command Buttons.