You are on page 1of 6

4/7/2015

Design a VBA User Form - MultiPage Controls, Labels, Textboxes

Excel VBA Programming


Home
Getting Started
8 part section >>
VBA Programming Variables
6 Part Section >>
Conditional Logic
9 part section >>
Strings and String Functions
8 Part Section >>
Programming Loops
4 Part Section >>
Programming Arrays
4 Part Section >>
Subs and Functions
6 Part Section >>
Excel VBA and Text Files
2 Part Section >>
Excel VBA and User Forms
5 part section >>
An Excel Picture Viewer Project
Excel Picture Viewer
Design the User Form
Option and Command Buttons
Add New Photo Tab
Form Initialize Event
Get Textbox data
VBA Option Button Code
ImageBox VBA Code
Next and Previous Buttons
Add New Photo Button
Save New Image
Copy an Image with Excel VBA
Excel VBA and Charts
4 part section >>
A TreeView Project
A 6 part section >>

http://www.homeandlearn.org/designing_the_user_form.html

1/6

4/7/2015

Design a VBA User Form - MultiPage Controls, Labels, Textboxes

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

Top 10 eCommerce Software


See Best eCommerce Software in 2015 Top Vendor Report. Download Now.

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:
http://www.homeandlearn.org/designing_the_user_form.html

2/6

4/7/2015

Design a VBA User Form - MultiPage Controls, Labels, Textboxes

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:

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:

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:

Clicking the button brings up the Font dialogue box:

http://www.homeandlearn.org/designing_the_user_form.html

3/6

4/7/2015

Design a VBA User Form - MultiPage Controls, Labels, Textboxes

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:

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:
Label2
Caption: Date Taken
Width: 72
Top: 102
Label3
Caption: Information
Width: 66
http://www.homeandlearn.org/designing_the_user_form.html

4/6

4/7/2015

Design a VBA User Form - MultiPage Controls, Labels, Textboxes

Top: 132
Label4
Caption: Dimensions
Width: 66
Top: 162
Label5
Caption: Image Size
Width: 54
Top: 192
Label6
Caption: Camera
Width: 54
Top: 222
Label7
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:
TextBox1
Name: txtFileName
Top: 66
TextBox2
Name: txtDate
Top: 102
TextBox3
Name: txtInfo
Top: 132
TextBox4
Name: txtDimensions
Top: 162
TextBox5
Name: txtSize
http://www.homeandlearn.org/designing_the_user_form.html

5/6

4/7/2015

Design a VBA User Form - MultiPage Controls, Labels, Textboxes

Top: 192
TextBox6
Name: txtCamera
Top: 222
Your form should now look like this:

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

Option Buttons and the Command Buttons >


Lots more free online course here on our main Home and Learn site
All course material copyright Ken Carney

http://www.homeandlearn.org/designing_the_user_form.html

6/6

You might also like