Customizing the Toolbox


When a UserForm is active in the VBE, the Toolbox displays the controls that you can add to the UserForm. This section describes ways to customize the Toolbox.

Changing icons or tip text

If you would prefer a different icon or different tip text for a particular tool, right-click the toolbox control and select Customize xxx from the shortcut menu (where xxx is the control's name ). This brings up a new dialog box that lets you change the ToolTip text, edit the icon, or load a new icon image from a file.

Adding new pages

The Toolbox initially contains a single tab. Right-click this tab and select New Page to add a new tab to the Toolbox. You can also change the text displayed on the tab by selecting Rename from the shortcut menu.

Customizing or combining controls

A very handy feature lets you customize a control and then save it for future use. You can, for instance, create a CommandButton control that's set up to serve as an OK button. For example, you can set the following properties: Width , Height , Caption , Default , and Name . Then drag the customized CommandButton to the Toolbox. This will create a new control. Right-click the new control to rename it or change its icon.

You can also create a new Toolbox entry that consists of multiple controls. For example, you can create two CommandButtons that represent a UserForm's OK and Cancel buttons. Customize them as you want and then select them both and drag them to the Toolbox. In this case, you can use this new Toolbox control to add two customized buttons in one fell swoop.

This also works with controls that act as containers. For example, create a Frame control and add four customized OptionButtons, neatly spaced and aligned. Then drag the Frame to the Toolbox to create a customized Frame control.

Tip  

You might want to place your customized controls on a separate page in the Toolbox. This lets you export the entire page so you can share it with other Excel users. To export a Toolbox page, right-click the tab and select Export Page.

CD-ROM  

The companion CD-ROM contains a PAG file (named image from book  newcontrols.pag ) that contains some customized controls. You can import this file as a new page in your Toolbox. Right-click a tab and select Import Page. Then locate the PAG file. Your Toolbox will resemble Figure 13-14. The new controls are: an exclamation point image, a "critical" red — image, a question mark image, an information image, an OK and Cancel button, a Frame with four OptionButton controls, a TextBox and a Spinner, and six CheckBox controls.

image from book
Figure 13-14: The Toolbox, with a new page of controls.

Adding new ActiveX controls

UserForms can use other ActiveX controls developed by Microsoft or other vendors . To add an additional ActiveX control to the Toolbox, right-click the Toolbox and select Additional Controls. This will display the dialog box shown in Figure 13-15.

image from book
Figure 13-15: The Additional Controls dialog box lets you add other ActiveX controls.

The Additional Controls dialog box lists all ActiveX controls that are installed on your system. Select the control(s) that you want to add and then click OK to add an icon for each selected control.

Caution  

Not all ActiveX controls that are installed on your system will work in Excel UserForms. In fact, most of them probably won't work. Also, some controls require a license in order to use them in an application. If you (or the users of your application) aren't licensed to use a particular control, an error will occur.




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