The Command Bar Object

Toolbars, menu bars, menus, submenus, and shortcut menus are all CommandBar objects. (A shortcut menu is a menu that pops up in response to a right mouse click.) Thus, every item pictured in Figure 12-2 is a command bar except the popup controls and the button control.

Of course, toolbars, menu bars, and shortcut menus are "top level" objects, whereas menus and submenus emanate from toolbars, menu bars, or shortcut menus.

It is important to note that Office VBA does not treat each of these CommandBar objects in the same way. For instance, the Count property of the CommandBars collection counts only the toplevel items: menu bars, toolbars, and shortcut menus. It does not count menus or submenus. Also, the Add method of the CommandBars collection can be used to create toolbars or menu bars, but not menus or submenus.

The CommandBar object has a Type property that can assume one of the constants in the following enum:

Enum MsoBarType msoBarTypeNormal = 0 ' toolbar msoBarTypeMenuBar = 1 ' menu bar msoBarTypePopup = 2 ' menu, submenu, or shortcut menu End Enum

0 0

Post a comment