CmdNum Property [Visio 2003 SDK Documentation]
Gets or sets the command ID associated with an accelerator, menu, menu item, or toolbar item.
object**.CmdNum** = intVal
intVal = object**.CmdNum**
object Required. An expression that returns an AccelItem, Menu, MenuItem, or ToolbarItem object.
intVal Required Integer. The command ID of the object.
Version added
4.0
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 for a MenuItem object that represents a submenu should be zero (0). 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 aren't 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 Microsoft Office Visio after you run this macro, call the ThisDocument.ClearCustomToolbars method.
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 "fullpath\filename"
'Tell Visio to actually use the new custom UI.
ThisDocument.SetCustomToolbars vsoUIObject
End If
End Sub
Applies to | AccelItem object | Menu object | MenuItem object | ToolbarItem object
See Also | AddOnName property | IsHierarchical property