Microsoft Office Tutorials and References
In Depth Information
12.1.3.1 Popup controls
12.1.3.1 Popup controls
A command-bar control of type msoControlPopup is a control whose sole purpose is to pop up
a menu (when the control is on a menu bar) or a submenu (when the control is on a menu). These
controls are naturally referred to as popup controls (see Figure 12-2 ) . Popup controls that are
located on a menu bar take on the appearance of a recessed button when the mouse pointer is over
the control. Popup controls on a menu or submenu have a small arrow on the far right to identify
them.
Thus, the term popup is used in two different ways. A popup control is a command-bar control of
type msoControlPopup and is used to pop up a menu or submenu. A popup command bar is a
command bar of type msoBarTypePopup and is either a menu, submenu, or shortcut menu. Note
that to display a popup command bar, the user needs to activate a popup control.
12.1.3.2 Button controls
A command-bar control of type msoControlButton is called a button control . When a button
control is activated (using an accelerator key or mouse click), a macro is executed. Button controls
have a string property called OnAction, which we can set to the name of the macro that is
executed when the control is activated.
12.1.4 Adding a Menu Item
It is worth mentioning now that there are a few counterintuitive wrinkles in the process of menu
creation. In particular, we might think at first that adding a new menu should be done using the
Add method of the CommandBars collection, specifying the name of the parent menu and the
location of the new menu on the parent. After all, a menu is a CommandBar object, and this
procedure would be consistent with other cases of adding objects to a collection.
However, this is not how it is done. Instead, as we will see, a new menu (or submenu) is created
by adding a command-bar control of type msoControlPopup to the CommandBarControls
collection of the parent menu (and specifying the new control's position on the parent). Actually,
this represents a savings of effort on our behalf. For, as we have remarked, a menu or submenu
requires a popup control for activation. Thus, Microsoft makes the task of creating menus and
submenus easier by automatically creating the corresponding (empty) menu or submenu in
response to our creation of a popup control. (We will see an example of this later, so don't worry
too much if this is not perfectly clear yet.)
One word of advice before proceeding: As we will see, when creating a new toolbar or menu, you
can set one of the parameters to make the object temporary, meaning that it will be destroyed
when Excel is closed. In this way, if anything unexpected happens, it is easy to recover—just
close Excel and reopen it. Alternatively, by opening the Customize dialog box (from the Tools
menu), you can delete menu items by dragging them off of the menu, and you can delete toolbars
by using the Delete button.
12.2 The CommandBars Collection
The topmost object that relates to menus and toolbars is the CommandBars collection, which
contains all of the application's CommandBar objects. The CommandBars collection is accessible
through the CommandBars property of the Application object, that is:
Application.CommandBars
 
Search JabSto ::




Custom Search