Microsoft KB Archive/160473

= XL97: How to Create a Template for a Toolbox Control =

Article ID: 160473

Article Last Modified on 10/10/2006

-

APPLIES TO


 * Microsoft Excel 97 Standard Edition

-



This article was previously published under Q160473





SUMMARY
The UserForm Toolbox in the Visual Basic Editor contains all the default controls that you can add to a UserForm. You can add other custom controls that are installed on your computer. For example, you can add a third type of control that is a "template" for a control that you already customized.

This article describes the process for customizing an existing control and adding a template of the control to the Toolbox.



MORE INFORMATION
A template control retains all the properties you specify, which makes it easier to use than resetting the properties of the same default control each time you add the control to a UserForm.

Creating a Template Control
To create a template CommandButton control, and then add it to the Toolbox, use the following steps:  Close and save all workbooks in Microsoft Excel. Open a new workbook. Start the Visual Basic Editor (press ALT+F11). In the Visual Basic Editor, click UserForm on the Insert menu.

This step adds a UserForm to the project. (The Toolbox also appears.) Add a CommandButton control to the UserForm. If the Properties window is not visible, click Properties Window on the View menu.</li>  In the Properties window, change the following properties for the CommandButton to the following values. <pre class="fixed_text">      Property          Value ---      BackColor         Red Caption          My button ControlTipText   This is my button Font             Courier New

NOTE: If you fail to complete the next three steps, the template control may not be added permanently to the Toolbox. </li> On the File menu, click "Close and Return to Microsoft Excel".</li> Close and save the file.</li> Reopen the file and restart the Visual Basic Editor.</li> Drag the customized CommandButton that is on the UserForm onto the Controls tab of the Toolbox.

This step copies the CommandButton to the Toolbox, which adds a control that uses all the properties of the CommandButton you created in steps 5 through 7.</li> Click the control in the Toolbox that you created in Step 11, and then add this control to the UserForm.</li></ol>

The control you added to the UserForm is a template of the control you created earlier. Note that it is not necessary to add a default CommandButton, and then modify all the properties again.

NOTE: The Name properties for the CommandButtons you add to the UserForm are CommandButton1 and CommandButton2. The Name property is the only property that is different when you use the template control to add a CommandButton to a UserForm.

Deleting a Template Control
To delete a template control from the Toolbox, use the following steps:
 * 1) Right-click the template control in the Toolbox.
 * 2) Click Delete New CommandButton on the shortcut menu that appears.

<div class="references_section">