bottom
Great WordTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > WordTips Home > Macros > WordBasic Examples > Changing Toolbar Buttons with WordBasic

Changing Toolbar Buttons with WordBasic

Summary: How to make your custom toolbar buttons change their appearance in a WordBasic macro. (This tip works with Microsoft Word 6, and Word 95.)

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."

WordBasic allows you to select button faces from a group of built-in images, and you can change them on the fly. Even though the available images are quite diverse, selecting the images you want will necessarily involve some compromises on you part. You can see the complete list of available button faces by searching for the "toolbar button images and numbers" in the Help system (use Find, not the Index). The following WordBasic macro can be assigned to a button on the "switcher" toolbar:

Sub MAIN
   REM First check if the toolbar is shown or hidden
   If ToolbarState("sampler") Then
      REM Hide the toolbar and change the button image to "show"
      ViewToolbars .Toolbar = "sampler", .Context = 0, .Hide
      ChooseButtonImage .Face = 37, .Button = 1, .Context = 0, .Toolbar = "switcher"
   Else
      REM Show the button and change the button image to "hide"
      ViewToolbars .Toolbar = "sampler", .Context = 0, .Show
      ChooseButtonImage .Face = 39, .Button = 1, .Context = 0, .Toolbar = "switcher"
   End If
End Sub

When you click on the button on the "switcher" toolbar, the "sampler" toolbar is either displayed or hidden, depending on the state of the toolbar when you click on the button. In addition, the image used on the "switcher" toolbar button is changed from an up arrow to a down arrow. You can use different images from the built-in library by changing the values you assign to the .Face variable.

Tip #1121 applies to Microsoft Word versions: 6 | 95


Save Time! WordTips has been published weekly since early 1997. Past issues are available in convenient WordTips archives. Have your own enhanced archive of WordTips at your fingertips, available to use at any time!
 
Check out WordTips Archives today!

Helpful Links

Ask a Word Question
Make a Comment

Tips.Net Home
Vital News Home

WordTips FAQ
WordTips Premium

Learn Access Now

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

Advertise on the
WordTips Site

 

Great Info!

Get tips like this every week in WordTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)