Chapter 11

Creating Menus and Toolbars

To use most of Microsoft Office's tools and access much of its functionality, you typically need to click an item on a menu, click a button, or make selections from a drop-down list on a toolbar. Menus and toolbars are the interfaces between you and the Office tools, just as they'll be between your users and the custom Microsoft Visual Basic for Applications programs that you develop. Internally, Office makes no distinction between menus and toolbars. Office refers to all menus, including submenus and shortcut menus, and all toolbars as command bars. Anything that contains a command that the user clicks or interacts with is considered a command bar control and it exists on a command bar. The command bar can appear as either a menu, a toolbar, or a combination of both. Menus and submenus can exist on a toolbar; buttons can exist on the menu bar.

You can modify any built-in menu bar or toolbar, and you can create and modify custom toolbars, menu bars, and shortcut menus to include in 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. For example, the New, Open, and Save commands on the File menu in Word, Excel, and PowerPoint are also displayed, by default, as the first three buttons on the Standard toolbar.

The CommandBar object model represents both menus and toolbars in all Office applications. Consequently, a toolbar or menu may be referred to as a command bar within the context of Visual Basic programming. Every toolbar and menu bar available to you in an Office application is considered a CommandBar object. Depending on what items you place on it, the command bar may appear as a menu bar, a toolbar, or a hybrid. You can easily reuse any code you write that accesses and manipulates menus and toolbars within Word, Excel, PowerPoint, Microsoft Access, or Microsoft Outlook, because the CommandBar object model resides in the shared Microsoft Office 9.0 Object Library.