Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Overview of Command Bars

Office 2007
The use of CommandBars in some Microsoft Office applications has been superseded by the new Ribbon user interface. For more information, search help for the keyword "Ribbon."

In Microsoft Office, toolbars, menu bars, and shortcut menus are all controlled programmatically as one type of object: command bars. All the following items are represented in Visual Basic for Applications by CommandBar objects:

  • Menu bars, toolbars, and shortcut menus
  • Menus on menu bars and toolbars
  • Submenus on menus, submenus, and shortcut menus

You can modify any built-in menu bar or toolbar, and you can create and modify custom toolbars, menu bars, and shortcut menus to deliver with your Visual Basic application. You present the features of your application as individual buttons on toolbars or as groups of command names on menus. Because toolbars and menus are both command bars, you use the same kind of controls on both of them. For example, the docked toolbar shown in the following illustration contains three buttons.

A docked toolbar containing three buttons

The menu shown in the following illustration contains the same three commands as in the previous illustration, but here they're displayed as menu items.

A menu containing three menu items

In Microsoft Office, menu bars and toolbars can both contain menus. The floating toolbar shown in the following illustration contains three buttons, and it also contains a menu with the same three commands displayed as menu items.

A floating toolbar containing three buttons and a menu with three menu items

In Visual Basic, buttons and menu items are represented by CommandBarButton objects. The pop-up controls that display menus and submenus are represented by CommandBarPopup objects. In the following illustration, the control named "Menu" and the control named "Submenu" are both pop-up controls that display a menu and a submenu, respectively. Both the menu and the submenu are unique CommandBar objects with their own set of controls.

Popup controls that display a menu and a submenu

In Microsoft Office, you can also add text boxes, drop-down list boxes, and combo boxes to any command bar. These three types of controls are all represented in Visual Basic by CommandBarComboBox objects.

Aa433256.vs_note(en-us,office.12).gif  Note
Although they share similar appearances and behaviors, command bar controls and ActiveX controls aren't the same. You cannot add ActiveX controls to command bars, and you cannot add command bar controls to documents or forms.

The built-in command bar controls in container applications are also represented in Visual Basic by CommandBarButton, CommandBarPopup, and CommandBarComboBox objects, even though their appearances and behaviors may be more complex than the controls you can add yourself. Although you can modify the location and appearance of built-in controls, you cannot modify their built-in behavior. You can, however, assign a custom macro to any built-in control to completely replace its built-in behavior.




Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.