Page 310 - Excel Progamming Weekend Crash Course
P. 310
r540629 ch22.qxd 9/2/03 9:35 AM Page 285
Session 22 — A User Form Example 285
Part 1: Creating the Workbook
The first task to complete is creating the Addresses workbook. Follow these steps:
1. Start Excel to open a new, blank workbook.
2. Rename Sheet1 to Addresses by double-clicking the name tab on the worksheet
and then entering the new name.
3. Enter the data column headings as shown in Figure 22-1. You can format these any
way you want, but be sure they are in cells A2 through F2.
4. Save the workbook as Addresses.
At this point the workbook template is complete, and you can proceed with designing
the user form.
Part 2: Designing the Form
To create the new, blank user form and set its properties:
1. Press Alt+F11 to open the VBA Editor.
2. In the Project window, click the entry labeled VBAProject (Addresses).
3. Select Insert ➪ UserForm to add a new user form to the project.
4. Use the Properties window to change the form’s Name property to frmAddresses and
its Caption property to Address Entry.
The next steps add the TextBox controls for data entry, a ComboBox control for the
states, CommandButton controls for the actions, and Label controls to identify each text
box and the list box.
1. Add a TextBox control to the form, and change its Name property to txtFirstName.
2. Add a Label control next to the TextBox, and change its Caption property to
First Name:.
3. Add four more TextBox controls, changing the Name properties to txtLastName,
txtAddress, txtCity, and txtZip.
4. Put a Label control next to each of the new TextBox controls, and set the
Caption properties to Last Name:, Address:, City:, and Zip Code:.
5. Add a ComboBox control to the form and change its Name property to cmbStates.
Change its Style property to fmStyleDropDownList.
6. Put a Label control next to the ComboBox with the Caption property set to State:.
7. Add a CommandButton control. Change its Name property to cmdDone and its
Caption property to Done.
8. Add another CommandButton control. Change its Name property to cmdNext, its
Caption property to Next, and its Default property to True.
9. Add a third CommandButton control. Change its Name property to cmdCancel, its
Caption property to Cancel, and its Cancel property to True.

