OFF2001: How to Customize a Toolbar Button (275051)



The information in this article applies to:

  • Microsoft Excel 2001 for Mac
  • Microsoft PowerPoint 2001 for Macintosh
  • Microsoft Word 2001 for Macintosh

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:
  1. Close and save any open files, and then open a new document, workbook, or presentation.
  2. On the Tools menu, click Macro, and then select Visual Basic Editor (or press OPTION+F11).
  3. On the Insert menu, click Module.
  4. On the View menu, click Code to display the code window if it is not visible.
  5. In the module code window, type the following code:
    Sub HelloWorld()
       MsgBox "Hello, World!"
    End Sub
    					
  6. On the File menu, click Close and Return to Microsoft Product name.
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 "smiley face" 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 "Hello, World!".

REFERENCES

For more information about creating custom toolbar buttons, follow these steps:
  1. On the Help menu, click Contents and Index, click Index, and then click C.
  2. Scroll down until you locate Customize, and then click the arrow to the left to view a list of topics under the general topic.
  3. Click Customize menus and toolbars.
If you cannot find the information that you want, ask the Office Assistant.


Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbhowto kbProgramming KB275051