CommandBars property

Microsoft Visio Developer Reference

CommandBars property

       

Returns a reference to the CommandBars collection that represents the command bars in the container application.

Version added

2002

Syntax

objsRet = object.CommandBars

objsRet

The collection of CommandBar objects that represent command bars in the container application.

object

Required. An expression that returns an Application object.

Remarks

Beginning with Microsoft Visio 2002, a program can manipulate menus and toolbars in the Visio user interface by manipulating the CommandBars collection returned by the CommandBars property. The CommandBars collection has an interface identical to the CommandBars collection exposed by the suite of Microsoft Office applications such as Microsoft Word and Microsoft Excel.

Alternatively, since Visio version 4.0, Visio has exposed application and document properties that return a UIObject object that provides similar functionality to CommandBars. Consequently, programs can manipulate the Visio menus and toolbars using either the CommandBars collection or UIObject objects.

To get information about the object returned by the CommandBars property:

  1. On the Tools menu, point to Macros, and then click Visual Basic Editor.
  1. On the View menu, click Object Browser.
  1. In the Project/Library list, click Office.

If you do not see the Office type library in the Project/Library list, on the Tools menu, click References, select the Microsoft Office 10.0 Object Library check box, and then click OK.

  1. Under Classes, examine the class named CommandBars.

Note Each CommandBarControl object in a CommandBars collection has an OnAction and Context property whose values are determined by the container application. In Visio:

  • The OnAction property is a String value that is interpreted either as a COM add-in, a Visual Basic for Applications (VBA) macro, VBA code or as a Visio add-on name.
  • The Context property determines in which menu context a command bar appears. The menu context number is a String value (for example visUIObjSetDrawing or "2"), which is followed by an asterisk if the command bar is visible by default (for example, visUIObjSetShapeSheet & "*" or "4*"). Valid menu contexts are visUIObjSetDrawing (2), visUIObjSetStencil (3), visUIObjSetShapeSheet (4), visUIObjSetIcon(5), or visUIObjSetPrintPreview (7). Attempting to set the Context property to any other value will fail.

For more information about using the OnAction and Context properties in Visio, see Developing Visio Solutions on the Microsoft Developer Network (MSDN) Web site.

Example

'This macro demonstrates using the CommandBars property
'to list the command bars.

Public Sub IterateCommandBars()

    Dim myCommandBars As CommandBars
    Dim myCommandBar As CommandBar

    'Get the set of CommandBars
    'for the application
    Set myCommandBars = Application.CommandBars

    'List each CommandBar in
    'the Immediate window
    For Each myCommandBar In myCommandBars
        Debug.Print myCommandBar.Name
    Next

End Sub