XL97: How to Create a Template for a Toolbox Control

Last reviewed: February 27, 1998
Article ID: Q160473
The information in this article applies to:
  • Microsoft Excel 97 for Windows

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:

  1. Close and save all workbooks in Microsoft Excel.

  2. Open a new workbook.

  3. Start the Visual Basic Editor (press ALT+F11).

  4. In the Visual Basic Editor, click UserForm on the Insert menu.

This step adds a UserForm to the project. (The Toolbox also appears.)

  1. Add a CommandButton control to the UserForm.

  2. If the Properties window is not visible, click Properties Window on the View menu.

  3. In the Properties window, change the following properties for the CommandButton to the following values.

           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.

  1. On the File menu, click "Close and Return to Microsoft Excel".

  2. Close and save the file.

  3. Reopen the file and restart the Visual Basic Editor.

  4. 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.

  1. Click the control in the Toolbox that you created in Step 11, and then

        add this control to the UserForm.
    

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.

REFERENCES

For more information about customizing toolbox controls, click the Index tab in Visual Basic for Applications Help, type the following text

   toolbox

and then double-click the selected text to go to the "Add a customized control to the Toolbox" topic.


Additional query words: 97 XL97
Keywords : kbprg kbtool kbui xlvbahowto xlvbainfo xlui
Version : WINDOWS:97
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.