Table of contents
Collapse the table of content
Expand the table of content

Page.ShapeIDsToUniqueIDs Method (Visio)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Returns an array of unique IDs of shapes on the page, as specified by their shape IDs.


expression . ShapeIDsToUniqueIDs( ShapeIDs() , UniqueIDArgs , GUIDs() )

expression An expression that returns a Page object.


NameRequired/OptionalData TypeDescription
ShapeIDs()RequiredLongAn array of type Long of shape IDs corresponding to a set of shapes on the active drawing page.
UniqueIDArgsRequiredVisUniqueIDArgsGets, deletes, or makes the unique ID of a Shape object. See Remarks for possible values.
GUIDs()RequiredStringOut parameter. An empty array that the method fills with unique IDs of type String corresponding to the shapes specified in ShapeIDs()

Return Value



Microsoft Visio identifies shapes by two different IDs: shape IDs and unique IDs. Shape IDs are numeric and uniquely identify shapes within the scope of an individual drawing page. They are not unique within a wider scope, however.

Unique IDs are globally unique identifiers (GUIDs). They are unique within the scope of the application.

To convert between shape IDs and unique IDs, you can use two methods of the Page object, ShapeIDsToUniqueIDs and UniqueIDsToShapeIDs .

By default, a shape does not have a unique ID. A shape acquires a unique ID only if you set its Shape.UniqueID property. If a Shape object has a unique ID, no other shape in any other document will have the same ID.

The UniqueIDArgs parameter sets and controls the behavior of the UniqueID property for all the shapes in ShapeIDs() . UniqueIDArgs should have one of the following values declared in the Visio type library in VisUniqueIDArgs .

visGetGUID0Returns the unique ID string only if the shape already has a unique ID. Otherwise it returns a zero-length string ("").
visGetOrMakeGUID1Returns the unique ID string of the shape. If the shape does not yet have a unique ID, it assigns one to the shape and returns the new ID.
visDeleteGUID2Deletes the unique ID of a shape and returns a zero-length string ("").
visGetOrMakeGUIDWithUndo3Returns the unique ID string of the shape. If the shape does not already have a unique ID, assigns one to the shape and returns the new ID. Undoable.
visDeleteGUIDWithUndo4Clears the unique ID of a shape and returns a zero-length string (""). Undoable.


The following Microsoft Visual Basic for Applications (VBA) macro shows how to use the ShapeIDsToUniqueIDs method to determine the unique IDs of the shapes on the page passed to the method. It iterates through all the shapes on the active drawing page, using the Shape.UniqueID property to get the shape IDs of the shapes, and then passes an array of those IDs to the ShapeIDsToUniqueIDs method as the ShapeIDs() parameter to get the unique IDs of the shapes. For the UniqueIDArgs parameter, it passes the value visGetOrMakeGUID , telling Visio to create a unique ID for any shape that doesn't already have one. It prints the unique IDs and shape IDs to the Immediate window.

Before running this macro, open a Visio drawing and place several shapes on the active drawing page.

Public Sub ShapeIDsToUniqueIDs_Example()
    Dim vsoShape As Visio.Shape 
    Dim intArrayCounter As Integer 

    intShapeCount = ActivePage.Shapes.Count 

    ReDim alngShapeIDs(intShapeCount - 1) As Long 
    ReDim astrUniqueIDs(intShapeCount - 1) As String 

    intArrayCounter = 0 

    For Each vsoShape In ActivePage.Shapes 
        alngShapeIDs(intArrayCounter) = vsoShape.ID 
        Debug.Print alngShapeIDs(intArrayCounter) 
        intArrayCounter = intArrayCounter + 1 

    ActivePage.ShapeIDsToUniqueIDs alngShapeIDs, visGetOrMakeGUID, astrUniqueIDs 

    intArrayCounter = 0 

    For intArrayCounter = LBound(astrUniqueIDs) To UBound(astrUniqueIDs) 
        Debug.Print astrUniqueIDs(intArrayCounter) 

End Sub
© 2018 Microsoft