Changing Toolbar Buttons with VBA

Written by Allen Wyatt (last updated June 25, 2018)
This tip applies to Word 97, 2000, 2002, and 2003


There are certain toolbar buttons that when you press them, they change to have a different appearance. For instance, if you press on the Bold tool, the tool takes on a different look, as if it is depressed. This is done by Word by using two different button graphics. The first is the "unselected" appearance, and the other is displayed when the button has been clicked.

You can use a similar trick with your custom toolbar buttons. As an example of how this could work, let's say that you have a toolbar that you use a lot. You have named this toolbar "sampler." You want this toolbar to be displayed when you click a button on a different toolbar. First, you need to create the new toolbar that will contain the single button that toggles the "sampler" toolbar. In this example, the new toolbar will be named "switcher." The following VBA macro can be assigned to a button on the "switcher" toolbar:

Sub SwitchTools()
    ' First check if the toolbar is shown or hidden
    If CommandBars("sampler").Visible Then
        ' Hide the toolbar and change the button image to "normal"
        CommandBars("sampler").Visible = False
        CommandBars("switcher").Controls(1).State. = msoButtonUp
    Else
        ' Show the button and change the button image to "selected"
        CommandBars("sampler").Visible = True
        CommandBars("switcher").Controls(1).State = msoButtonDown
    End If
End Sub

This macro toggles the state of the button (using msoButtonUp and msoButtonDown) to make it have the desired appearance.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1122) applies to Microsoft Word 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Zooming with the Keyboard

Want to zoom in and out without the need to using the ribbon tools? You can create your own handy macros that do the ...

Discover More

Printing Shortcut Key Assignments from a Macro

Need to know what shortcut keys are defined? You can use a single macro command line to print out the definitions.

Discover More

Displaying Multiple Filtered Colors

The filtering capabilities of Excel are quite helpful in taming a large amount of data. While you can filter by color, ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Inserting a Break with a Macro

Inserting a break in your document is easy. You may think that inserting one using a macro is more complex, but it isn't. ...

Discover More

Determining Word Frequency

How to construct a word frequency list.

Discover More

Understanding the For ... Next Structure

Spend any time creating Word macros, and sooner or later you will need to repeat some of your programming code a certain ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 8?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.