Word

Create Toggle Button for a Command Bar

Ease of Use

Easy

Version tested with

2002 

Submitted by:

Jacob Hilderbrand

Description:

Demonstrates how to create a toggle button to turn on or off a Word toolbar. This examples turns on the Function Keys toolbar. 

Discussion:

Do you find yourself often turning on a specific toolbar? This macro demonstrates how to use VBA to create a toggle button for a toolbar, much like the Drawing Toolbar toggle button found on Word's Standard toolbar. Our sample displays the Function Keys (F1 - F12) Toolbar. The Function Keys provide some useful shortcuts. There is a built-in Command Bar that you can toggle on and off with this macro. 

Code:

instructions for use

			

Option Explicit Sub ShowFunctionKeysCommandBar() CommandBars("Function Key Display").Visible = Not _ (CommandBars("Function Key Display").Visible) End Sub

How to use:

  1. Open Word.
  2. Press Alt + F11 to open Visual Basic Editor (VBE).
  3. In the Project Explorer select Normal (to have the macro available to all Word files).
  4. From the Menu, choose Insert-Module.
  5. Paste the code into the window at right.
  6. Hit the Save diskette.
  7. Press Alt + Q or press the X in the top right corner to close VBE.
 

Test the code:

  1. Tools | Macro | Macros
  2. Select "ShowFunctionKeysCommandBar" and press Run
 

Sample File:

FunctionKeysCommandBar.ZIP 5.65KB 

Approved by mdmackillop


This entry has been viewed 114 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express