Adding Controls to a User Form

To add controls to a UserForm, use the Toolbox. (The VBE does not have menu commands that add controls.) If the Toolbox is not displayed, choose View Toolbox. shows the Toolbox.

Toolbox ^S1


k A




|7 &




Figure 13-2: Use the Toolbox to add controls to a UserForm.

Click the Toolbox button that corresponds to the control that you want to add and then click inside the dialog box to create the control (using its default size). Or you can click the control and then drag in the dialog box to specify the dimensions for the control.

When you add a new control, it is assigned a name that combines the control type with the numeric sequence for that type of control. For example, if you add a commandButton control to an empty UserForm, it is named commandButtonl. If you then add a second CommandButton control, it is named CommandButton2.

Tip It's a good idea to rename all the controls that you will be manipulating with your VBA code. Doing so lets you refer to meaningful names (such as ProductListBox) rather than generic names (such as ListBoxl). To change the name of a control, use the Properties window in the VBE. Just select the object and change the Name property.


0 0

Post a comment