Creating the User Form

Figure 13-7 shows the finished UserForm for this example. For best results, start with a new workbook with only one worksheet in it. Then follow these steps:

Figure 13-7: This dialog box asks the user to enter a name and a sex.

1. Press Alt+F11 to activate the VBE.

2. In the Project window, select the workbook's project and choose Insert ^ UserForm to add an empty UserForm.

3. The UserForm's Caption property will have its default value: UserForm1. Use the Properties window to change the UserForm's Caption property to Get Name and Sex. (If the Properties window isn't visible, press F4.)

4. Add a Label control and adjust the properties as follows:

Property Value

Accelerator N

Caption Name:

TabIndex 0

5. Add a TextBox control and adjust the properties as follows:

Property

Name

TabIndex

Value

TextName 1

6. Add a Frame control and adjust the properties as follows:

Property

Value

Caption

Sex

TabIndex

2

7. Add an OptionButton control inside the Frame and adjust the properties

as follows:

Property

Value

Accelerator

M

Caption

Male

Name

OptionMale

TabIndex

0

8. Add another OptionButton control inside the Frame and adjust the properties as follows:

Property Value

Accelerator F

Caption Female

Name OptionFemale

TabIndex 1

9. Add yet another OptionButton control inside the Frame and adjust the properties as follows:

Property

Value

Accelerator

U

Caption

Unknown

Name

OptionUnknown

TabIndex

2

Value

True

10. Add a CommandButton control outside the Frame and adjust the properties

as follows:

Property

Value

Caption

OK

Default

True

Name

OKButton

Tablndex

3

11. Add another CommandButton control and adjust the properties as follows:

Property

Value

Caption

Cancel

Cancel

True

Name

CancelButton

Tablndex

4

When you are creating several controls that are similar, you may find it easier to copy an existing control rather than create a new one.To copy a control, press Ctrl while you drag the control to make a new copy of it. Then adjust the properties on the copied control.

0 0

Post a comment