AccelItem.CmdNum Property

Visio Automation Reference

Gets or sets the command ID associated with an accelerator, menu, menu item, or toolbar item. Read/write.

Version Information
 Version Added:  Visio 4.0

Syntax

expression.CmdNum

expression   A variable that represents an AccelItem object.

Return Value
Integer

Remarks

When the AddOnName property of a MenuItem or ToolbarItem object indicates an add-on to run, Microsoft Office Visio automatically assigns a CmdNum property.

The CmdNum property should never be zero for an AccelItem object.

To insert a separator in a menu preceding a MenuItem object or a spacer in a toolbar preceding a ToolbarItem object, use the BeginGroup property.

Valid command IDs are declared by the Visio type library in VisUICmds. They have the prefix visCmd.

Example

This Microsoft Visual Basic for Applications (VBA) macro shows how use the CmdNum property to get a particular built-in Visio toolbar button, and then it shows how to change the button's icon. The new icon persists as long as the document is active.

This macro assumes you are not using a custom user interface.

Before running this macro, replace fullpath\filename in the following code with the full path to and file name of an icon file (.ico) on your computer.

To restore the built-in toolbars in Visio after you run this macro, call the ThisDocument.ClearCustomToolbars method.

Visual Basic for Applications
  
Public Sub CmdNum_Example()
 
    Dim vsoUIObject As Visio.UIObject 
    Dim vsoToolbarSet As Visio.ToolbarSet   
    Dim vsoToolbarItems As Visio.ToolbarItems 
    Dim vsoToolbarItem As Visio.ToolbarItem 
    Dim intCounter As Integer
    Dim blsFound As Boolean
'Get the UIObject object for the copy of the Microsoft Office toolbars.
Set vsoUIObject = Visio.Application.BuiltInToolbars(0) 

'Get the drawing window toolbar sets.
'NOTE: Use ItemAtID to get the toolbar set.
'Using vsoUIObject.ToolbarSets(visUIObjSetDrawing) will not work.
Set vsoToolbarSet = vsoUIObject.ToolbarSets.ItemAtID(visUIObjSetDrawing) 

'Get the vsoToolbarItems collection.
Set vsoToolbarItems = vsoToolbarSet.Toolbars(0).ToolbarItems 

'Get the toolbar item for the Save toolbar button. 
blsFound = False
For intCounter = 0 To vsoToolbarItems.Count - 1

    Set vsoToolbarItem = vsoToolbarItems(intCounter) 
    If vsoToolbarItem.CmdNum = visCmdFileSave Then
        blsFound = True
        Exit For 

    End If 

Next intCounter 

If blsFound Then

    'Set the icon. 
    vsoToolbarItem.IconFileName <em>"fullpath\filename" </em>
    'Indicate to Visio to use the new custom UI. 
    ThisDocument.SetCustomToolbars vsoUIObject

End If

End Sub

See Also