Showing and Enabling Command Bar Controls

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

You specify whether a command bar control appears on a command bar by using its Visible property. You specify whether a command bar control appears enabled or disabled (grayed out) by using its Enabled property. For example, the following two lines of code could be used to toggle the Visible and Enabled properties of the named controls:

Application.CommandBars("Menu Bar").Controls("Edit").Enabled = _
   Not Application.CommandBars("Menu Bar").Controls("Edit").Enabled

Application.CommandBars("Formatting").Controls("Font").Visible = _
   Not Application.CommandBars("Formatting").Controls("Font").Visible

Note   The "Menu Bar" CommandBar object refers to the main menu bar in Microsoft® Word, Microsoft® PowerPoint®, and Microsoft® Access. The main menu bar in Microsoft® Excel is called "Worksheet Menu Bar." To experiment with sample code that refers to the "Menu Bar" CommandBar object in Excel, simply change the reference from "Menu Bar" to "Worksheet Menu Bar."

When a command bar control's Enabled property is False, the control appears on the command bar but is disabled and cannot be manipulated.

See Also

Working with Command Bars | Working with Command Bar Controls | Adding Controls to a Command Bar | Visually Indicating the State of a Command Bar Control