Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to Create a Template for a Toolbox Control


View products that this article applies to.

This article was previously published under Q213770

↑ Back to the top


Summary

The UserForm Toolbox in the Visual Basic Editor contains all of the default controls that you can add to a UserForm. You can also add other custom controls to the default Toolbox. For example, you can add a type of control that is a template for a control that you may have already created or customized.

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

↑ Back to the top


More information

A template control retains all the properties that you specify. This makes the control easier to use than having to reset the properties of the control each time you add it to a UserForm.

Creating a Template Control

Part One

To create a template command button control, and then add it to the UserForm Toolbox, follow these 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.

Part Two

To add a UserForm to the project (the Toolbox also appears), follow these steps:
  1. Add a command button 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 properties for the command button to the following values:
       Property          Value
       -----------------------------------
       BackColor         Red
       Caption           My button
       ControlTipText    This is my button
       Font              Courier New
    					

Part Three

To permanently add the new template control to the Toolbox, follow these steps:
  1. On the File menu, click Close and Return to Microsoft Excel.
  2. Save and close the file.
  3. Reopen the file, and then start the Visual Basic Editor.
  4. Drag the customized command button that is on the UserForm onto the Controls tab of the Toolbox.

Part Four

To copy the command button to the Toolbox, which adds a control that uses all the properties of the command button that you created in "Part Two," follow these steps:
  1. Click the control that you created in step 4 of "Part Three."
  2. Add this control to the UserForm.
The control that you added to the UserForm is a template of the control that you created earlier.

You do not need to modify the properties for the new command button again because the properties for the new command button have been updated automatically according to your template.

The Name properties for the command buttons that 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 command button to a UserForm.

Deleting a Template Control

To delete a template control from the Toolbox, follow these steps:
  1. Right-click the template control in the Toolbox.
  2. Click Delete New CommandButton on the shortcut menu that appears.

↑ Back to the top


References

For more information about customizing toolbox controls, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type toolbox in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB213770, kbui, kbprogramming, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 213770
Revision : 6
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 230