Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To make your custom toolbar button useful, you must first write a Visual Basic for Applications procedure to attach to the button. To create a simple Visual Basic procedure, follow these steps:
- Close and save any open workbooks, and then open a new workbook.
- Start the Visual Basic Editor (press ALT+F11).
- On the Insert menu, click Module.
- In the module, type the following code:
Sub HelloWorld()
MsgBox "Hello, World!"
End Sub
- Click Close and Return to Microsoft Excel on the File menu.
Now that you have created a simple Visual Basic procedure, follow these
steps to create a custom toolbar button:
- Click Customize on the Tools menu.
- Click the Commands tab in the Customize dialog box.
- Click Macros in the Categories list.
- In the Commands list, drag the Custom Button item and drop it on any toolbar where you want the custom toolbar button to appear.
The button now appears on the toolbar. To assign the HelloWorld macro to
the button, follow these steps:
- Click Modify Selection in the Customize dialog box. A menu appears with different options for your custom toolbar button.
- Click Assign Macro, click HelloWorld on the Macro Name list, and then click OK.
You may also want to change the ScreenTip that appears when you place the insertion point over the button. To change the ScreenTip, follow these steps:
- Click Modify Selection in the Customize dialog box.
A menu appears with different options for your custom toolbar button.
- In the Name box, type Hello, World!
To modify the image displayed for your custom button, follow these steps:
- Click Modify Selection in the Customize dialog box. A menu appears with different options for your custom toolbar button.
- On the menu, point to Change Button Image, and then click the image to display on the button.
Now click
Close in the
Customize dialog box. When you click the button you just added to the toolbar, you will see a message box with the text "Hello, World!" (without the quotation marks).