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:
- 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.
Part Two
To add a UserForm to the project (the
Toolbox also appears), follow these steps:
- Add a command button control to the UserForm.
- If the Properties window is not visible, click Properties Window on the View menu.
- 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:
- On the File menu, click Close and Return to Microsoft Excel.
- Save and close the file.
- Reopen the file, and then start the Visual Basic Editor.
- 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:
- Click the control that you created in step 4 of "Part Three."
- 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:
- Right-click the template control in the Toolbox.
- Click Delete New CommandButton on the shortcut menu that appears.