Share via


Working with Command Bars

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.

Microsoft Office applications all share the same technology for creating menus and toolbars, and this technology is available to you through the command bars object model. In Microsoft Office applications, there are three kinds of CommandBar objects: toolbars, menu bars, and pop-up menus. Pop-up menus are displayed in three ways: as menus that drop down from menu bars, as submenus that cascade off menu commands, and as shortcut menus. Shortcut menus (also called "right-click menus") are menus that appear when you right-click something.

Since the command bars object model is shared among all Office applications, you can write code to manipulate command bars that can be used in any Office application or custom solution you develop. This section will occasionally discuss using the Customize dialog box, but will emphasize programmatically creating, deleting, and manipulating CommandBar objects.

Note   You can create and modify menus and toolbars in your custom Office solutions through the host application's user interface by pointing to Toolbars on the View menu, and then clicking Customize. The functionality of the Customize dialog box differs slightly between Office applications. For more information about creating and customizing command bars by using the Customize dialog box, search the Help index for "toolbars, creating" in the Office application used to create your command bar.

Everything you can do in a host application by using the Customize dialog box you can also do by using VBA code. In addition, there are some things you can do only by using VBA code. For example, there is no way to copy a command bar from the Customize dialog box.

Understanding how to work with command bars in Office applications requires that you understand not only what they have in common across all applications (the command bars object model) but also how they differ within each application. The differences are covered in the next section; the similarities are covered in "Manipulating Command Bars and Command Bar Controls with VBA Code" later in this chapter.