Share via


Shapes.Item Property

Visio Automation Reference

Returns an item from a collection. The Item property is the default property for all collections. Read-only.

Version Information
 Version Added:  Visio 2.0

Syntax

expression.Item(NameUIDOrIndex)

expression   A variable that represents a Shapes object.

Parameters

Name Required/Optional Data Type Description
NameUIDOrIndex Required Variant Contains the name, unique ID, or index of the object to retrieve.

Return Value
Shape

Remarks

When retrieving objects from a collection, you can omit Item from the expression because it is the default property for all collections. The following statements are equivalent to the syntax example given above:

Visual Basic for Applications
  objRet = object(index) 
objRet = object(stringExpression)

You can retrieve an object in an Addons, Documents, Fonts, Hyperlinks, Layers, Masters, MasterShortcuts, OLEObjects, Pages, Shapes, or Styles collection by passing the object's name as a string expression in a Variant.

If you retrieve a Shape object by name, the Item property searches all shapes in the Shapes collection's containing page or containing master, in addition to the collection's containing shape. Therefore, the Shape object returned by the Item property can be a shape that is not in the Shapes collection.

You can also pass the unique ID string of a Master or Shape object to the Item property. For example:

Visual Basic for Applications
  objRet = vsoShapes.Item("{2287DC42-B167-11CE-88E9-0020AFDDD917}")

If such a string is passed to the Item property of a Shapes collection, all the shapes contained in the collection are searched. Shapes within the group shapes in the containing shape are not searched.

To search all shapes in the collection, plus the shapes inside groups and the containing shape of the collection, prefix the unique ID string with an asterisk (*). For example:

Visual Basic for Applications
  objRet = vsoShapes.Item("*{2287DC42-B167-11CE-88E9-0020AFDDD917}")

For more information about passing ID strings to the Item property, see the topic for the UniqueID property in this Automation Reference.

ms426112.vs_note(en-us,office.12).gif  Notes
  • In Visio 2000 only, Shapes.Item("{guid}") examined the Shapes collection's containing shape and all descendants, and Shapes.Item("*{guid}") examined all shapes in the Shapes collection's containing page or containing master.
  • Beginning with Microsoft Visio 2000, you can use both local and universal names to refer to Visio shapes, masters, documents, pages, rows, add-ons, cells, hyperlinks, styles, fonts, master shortcuts, UI objects, and layers. When a user names a shape, for example, the user is specifying a local name. Beginning with Microsoft Office Visio 2003, the ShapeSheet spreadsheet displays only universal names in cell formulas and values. (In prior versions, universal names were not visible in the user interface.)
    As a developer, you can use universal names in a program when you don't want to change a name each time a solution is localized. Use the Item property to access an object in the Masters, Pages, Shapes, Styles, Layers, or MasterShortcuts collection by using its local name. Use the ItemU property to access an object from one of these collections by using the object's universal name.

Example

This Microsoft Visual Basic for Applications (VBA) macro shows how to use the Item property to get a Page object from the Pages collection of the active document, and all the Shape objects in the Shapes collection of the Page object. It prints the names of all shapes on Page1 in the Immediate window.

Before running this macro, make sure that the active document has shapes on Page1.

Visual Basic for Applications
  
Public Sub Item_Example()
 
    Dim intCounter As Integer
    Dim intShapeCount As Integer
    Dim vsoShapes As Visio.Shapes 
Set vsoShapes = ActiveDocument.Pages.Item(1).Shapes 

Debug.Print "Shape Name List For..."
Debug.Print "Document: "; ActiveDocument.Name 
Debug.Print "Page: "; ActiveDocument.Pages.Item(1).Name 

intShapeCount = vsoShapes.Count 

If intShapeCount > 0 Then
    For intCounter = 1 To intShapeCount 
        Debug.Print " "; vsoShapes.Item(intCounter).Name 
    Next intCounter 
Else
    Debug.Print " No Shapes On Page" 
End If  

End Sub

See Also