O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Command Bar Controls

Initially, one of the most confusing aspects of the Office menu system is that the items that appear on a menubar are not menus, or even names of menus. Rather, they are controls of type CommandBarControl. Command bar controls can be added to a menubar, toolbar, menu, submenu, or shortcut menu.

Every command bar control is an object of type CommandBarControl. In addition, every command bar control is an object of one of the following three object types:

  • CommandBarButton

  • CommandBarComboBox

  • CommandBarPopup

This allows the various types of command bar controls to possess a common set of properties and methods (those of the CommandBarControl object), as well as an additional set of properties and methods that reflects the diversity of these controls. (After all, text boxes are quite different from popup controls, for instance.)

Creating a New Command Bar Control

To create and add a command bar control to a command bar, use the Add method of the CommandBarControls collection. This method returns a CommandBarButton, CommandBarComboBox, or CommandBarPopup object, depending on the value of the Type parameter (see later in this section). The syntax is:

CommandBarControlsObject.Add(Type, Id, Parameter, _
	                             Before, Temporary)

Type is the type of control to be added to the specified command bar. Table 21-1 shows the possible values for this parameter, along with the corresponding control and the return type of the Add method.

Table 21-1. msoControlType Values for the Type Parameter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required