Adding Controls to a UserForm


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 image from book Toolbox. Figure 13-2 shows the Toolbox.

image from book
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 CommandButton1 . 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 ListBox1 ). To change the name of a control, use the Properties window in the VBE. Just select the object and change the Name property.




Excel 2007 Power Programming with VBA
Excel 2007 Power Programming with VBA (Mr. Spreadsheets Bookshelf)
ISBN: 0470044012
EAN: 2147483647
Year: 2007
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net