Microsoft KB Archive/275051

= OFF2001: How to Customize a Toolbar Button =

Article ID: 275051

Article Last Modified on 1/29/2007

-

APPLIES TO


 * Microsoft Excel 2001 for Mac
 * Microsoft PowerPoint 2001 for Mac
 * Microsoft Word 2001 for Mac

-



This article was previously published under Q275051



For a Microsoft Excel 98 version of this article, see 183842.



SUMMARY
This article describes how to create a custom button on a toolbar and assign a macro to that custom button.



MORE INFORMATION
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 in any Office 2001 program, follow these steps:  Close and save any open files, and then open a new document, workbook, or presentation. On the Tools menu, click Macro, and then select Visual Basic Editor (or press OPTION+F11). On the Insert menu, click Module. On the View menu, click Code to display the code window if it is not visible.  In the module code window, type the following code: Sub HelloWorld MsgBox &quot;Hello, World!&quot; End Sub  On the File menu, click Close and Return to Microsoft .</li></ol>

Now that you have created a Visual Basic procedure, follow these steps to create a custom toolbar button:
 * 1) On the Tools menu, click Customize.
 * 2) Click the Commands tab in the Customize dialog box. If the tabs are obscured, move or close any toolbars necessary to allow you to click the Commands tab.
 * 3) Select Macros in the Categories list.
 * 4) In the Commands list box, select the custom button with the &quot;smiley face&quot; icon, and drag the icon to any toolbar where you want the custom toolbar button to appear.

The button appears on the toolbar. To assign the HelloWorld macro to the button, follow these steps.

NOTE: You can do this in the Customize dialog box or after you close the dialog box by clicking OK.
 * 1) Hold down CONTROL and click the new button on the toolbar. A contextual menu appears.
 * 2) Click Assign Macro.
 * 3) The Assign Macro dialog box appears. 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:
 * 1) Hold down CONTROL and click the new button.
 * 2) Select Properties from the contextual menu, and then type Hello, World! (without quotation marks) in the Name box to create a ScreenTip.
 * 3) If you are finished, click OK to close the Command Properties dialog box.

To modify the image that is displayed for your custom button, follow these steps:
 * 1) If the Command Properties dialog box is not visible, hold down CONTROL and click the new button.
 * 2) Select Properties from the contextual menu.
 * 3) Click the arrow next to the image for the button.
 * 4) Select one of the custom button faces from the palette of choices. You can also click Edit Button Image to edit the existing icon in the Button Editor dialog box.
 * 5) Click OK to close the Command Properties dialog box.

Now click OK in the Customize dialog box. When you click the button that you just added to the toolbar, you see a message box with the text &quot;Hello, World!&quot;.

<div class="references_section">