
Tips.Net > WordTips Home > Macros > VBA Examples > Changing Toolbar Buttons with VBA
Summary: Toolbar buttons can have a different appearance depending on their state—whether they have been clicked or not. This tip explains how you can create the two necessary versions of a toolbar button for your customizations. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 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.
Tip #1122 applies to Microsoft Word versions: 97 2000 2002 2003
Tremendous Table Tips! We often take tables for granted, but Word includes some very powerful ways you can present your tabular data. Discover how to make your tables better, easier to understand, and more effective.
Check out WordTips: Terrific Tables today!
Do you want a decade of WordTips information at your fingertips? You can find what you need with the WordTips Ten-Year Library. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips