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

Chapter 21. Menus and Toolbars

In this chapter:

  • An Overview

  • CustomizationContext

  • The CommandBars Collection

  • The CommandBar Object

  • Command Bar Controls

In this chapter, I discuss methods for programmatically controlling menus and toolbars. Even though the subject of menus and toolbars is fairly straightforward, it can seem very confusing, especially since the documentation (from Microsoft and others) is, in my opinion, very unenlightening. Let me see if I can clarify the subject.

An Overview

Actually, Word’s menu and toolbar objects do not belong to the Word object model. Instead, the menus and toolbars throughout Microsoft Office belong to the Office object model. The portion of the Office object model that relates to menus and toolbars is actually quite small, containing only two objects and their corresponding collections:

  • CommandBar objects and CommandBars collections

  • CommandBarControl objects and CommandBarControls collections

To help set the notation, Figure 21-1 shows the components of the Office menu structure.

Toolbars, menubars, menus, submenus, and shortcut menus (which are menus that pop up at various locations on the screen in response to a right mouse-click) are all CommandBar objects.

It is important to realize is that the “items” that you see on a toolbar, menubar, menu, or submenu are actually controls, called command bar controls; that is, they are CommandBarControl objects. As you will see, there are various types of command bar controls, falling into two broad ...

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