Share via


ItemAtID Property [Visio 2003 SDK Documentation]

Returns the AccelTable, MenuSet, or ToolbarSet object for an ID within a collection.

objRet = object**.ItemAtID**(IID)**

objRet     The object retrieved from the collection.

object     Required. An expression that returns an AccelTables, MenuSets, or ToolbarSets collection.

IID     Required Long. The Visio context ID of the object to retrieve.

Version added

4.0

Remarks

The ID corresponds to a window or context menu. Constants for IDs are prefixed with visUIObjectSet and are declared by the Visio type library in VisUIObjSets.

Example

This Microsoft Visual Basic for Applications (VBA) macro shows how to use the ItemAtID property to get a particular object in a collection. It also shows how to get a copy of the built-in Visio toolbars, add a toolbar button, set the button icon, and replace the built-in toolbar set with the custom set.

Before running this code, replace path\filename with the full path to and name of a valid icon (.ico) file on your computer.

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

Public Sub ItemAtID_Example()
 
    Dim vsoUIObject As Visio.UIObject 
    Dim vsoToolbarSet As Visio.ToolbarSet   
    Dim vsoToolbarItems As Visio.ToolbarItems 
    Dim vsoToolbarItem As Visio.ToolbarItem
 
    'Get the UIObject object for the copy of the built-in 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 ToolbarItems collection.
    Set vsoToolbarItems = vsoToolbarSet.Toolbars(0).ToolbarItems 

    'Add a new button in the first position.
    Set vsoToolbarItem = vsoToolbarItems.AddAt(0) 

    'Set properties for the new toolbar button. 
    vsoToolbarItem.CntrlType = visCtrlTypeBUTTON

    'Set the toolbar button caption. 
    vsoToolbarItem.Caption = "MyButton"

    'Set the toolbar button icon. 
    vsoToolbarItem.IconFileName "path\filename" 

    'Tell Visio to actually use the new custom UI. 
    ThisDocument.SetCustomToolbars vsoUIObject 

End Sub

Applies to | AccelTables collection | MenuSets collection | ToolbarSets collection

See Also | AccelTable object | AddAtID method | Item property | MenuSet object | SetID property | ToolbarSet object