1.8 Resize
Home and Learn - Free Excel VBA Course
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
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:
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.
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:
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
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
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
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.
Next Lesson: 10.3 Buttons >