Export (0) Print
Expand All
0 out of 2 rated this helpful - Rate this topic

Using Command Bars

Office 2007
The use of CommandBars in some Microsoft Office applications has been superseded by the new Ribbon user interface. For more information, search help for the keyword "Ribbon."

In general, to create or modify toolbars, menu bars, and shortcut menus that you want to deliver with your Visual Basic application, you should use the customization features of the container application. Changes made to toolbars, menu bars, and shortcut menus using the features of the container application are known as "design-time" changes. For information about using the container application to make design-time changes, see the online Help for that application.

You can add and modify toolbars, menu bars, and shortcut menus (and their component parts) by using the CommandBars portion of the Microsoft Office object model in Visual Basic code. You can write code that runs once to create toolbars and menu bars; in effect, the code simulates making design-time changes. In some container applications, however, you may be required to use a combination of this kind of Visual Basic code and the customization interface to design your Visual Basic application. The following are some common areas where you must use a combination of code and the container application's interface:

  • If your container application doesn't provide an interface for adding or modifying edit boxes, drop-down list boxes, or combo boxes on toolbars, you must use Visual Basic code to add and design one of these controls.
  • If your container application provides an interface for creating toolbars but doesn't provide one for creating a new menu bar, you'll need to create a menu bar by using Visual Basic. After you've created the menu bar in Visual Basic, you can design menus on that menu bar by using the container application's interface.
  • If your container application doesn't provide a way to display custom shortcut menus while the customization interface is displayed, you must use Visual Basic code to modify those shortcut menus.

You can also write code that exists in your Visual Basic application to make changes to toolbars and menu bars while your application is running (for example, you can write code to disable a command on a menu bar under certain conditions, or to add buttons to a toolbar in response to a user's actions). Changes brought about by your code while your Visual Basic application is running are known as "run-time" changes.

The following topics provide information about how you can make design-time and run-time changes to toolbars and menu bars from your Visual Basic code. You can search Help for:

Adding and Modifying Toolbars

Adding and Managing Menu Bars and Menu Items

Adding and Displaying Shortcut Menus

Aa433260.vs_note(en-us,office.12).gif  Note
The Task Pane is a type of CommandBar object that can be referenced as follows:
Dim cbTaskPane As CommandBar
Set cbTaskPane = Application.CommandBars("Task Pane")
MsgBox "The current task pane's title is """ & cbTaskPane.Controls(1).Caption & """"

However, many command bar methods and properties when applied to the Task Pane do not exhibit the same behavior as a normal CommandBar object. For example, the Delete and ShowPopup methods have no effect, nor does changing the value of the AdaptiveMenu, Context, Name, NameLocal, or Protection properties.




Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.