XL97: How to Customize a Custom Toolbar Button

Last reviewed: February 27, 1998
Article ID: Q161496
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SUMMARY

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

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

In order to make your custom toolbar button useful, you must first write a Visual Basic for Applications procedure to attach to the button. Follow these steps to create a simple Visual Basic procedure:

  1. Close and save any open workbooks, and then open a new workbook.

  2. Start the Visual Basic Editor (press ALT+F11).

  3. On the Insert menu, click Module.

  4. In the module type the following code:

          Sub HelloWorld()
             MsgBox "Hello, World!"
          End Sub
    
    

  5. 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:

  1. Click Customize on the Tools menu.

  2. Activate the Commands tab in the Customize dialog box.

  3. Select Macros in the Categories list box.

  4. In the Commands list box, 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:

  1. Click Modify Selection in the Customize dialog box. A menu appears with different options for your custom toolbar button.

  2. 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:

  1. Click Modify Selection in the Customize dialog box.

    A menu appears with different options for your custom toolbar button.

  2. In the Name box, type "Hello, World!" (without the quotation marks).

To modify the image displayed for your custom button, follow these steps:

  1. Click Modify Selection in the Customize dialog box. A menu appears with different options for your custom toolbar button.

  2. 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 quotation marks).

REFERENCES

For more information about creating custom toolbar buttons, click the Index tab in Microsoft Excel Help, type the following text

   buttons, toolbars

and then double-click the selected text to go to the "Add a button to a toolbar" topic.


Additional query words: 97 XL97 vba
Keywords : kbcode kbprg xlvbahowto xlui
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.