Shape.UniqueID property (Visio)

Gets, deletes, or makes the GUID that uniquely identifies the shape within the scope of the application. Read-only.

Syntax

expression. UniqueID( _fUniqueID_ )

expression An expression that returns a Shape object.

Parameters

Name Required/Optional Data type Description
fUniqueID Required Integer Gets, deletes, or makes the unique ID of a Shape object. See Remarks for possible values.

Return value

String

Remarks

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 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 UniqueID property.

If a Shape object has a unique ID, no other shape in any other document will have the same ID.

The fUniqueID parameter controls the behavior of the UniqueID property. It should have one of the following values declared in the Visio type library in VisUniqueIDArgs.

Constant Value Description
visGetGUID 0 Returns the unique ID string only if the shape already has a unique ID. Otherwise it returns a zero-length string ("").
visGetOrMakeGUID 1 Returns 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.
visDeleteGUID 2 Deletes the unique ID of a shape and returns a zero-length string ("").
visGetOrMakeGUIDWithUndo 3 Returns 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.
visDeleteGUIDWithUndo 4 Clears the unique ID of a shape and returns a zero-length string (""). Undoable.

To get a shape if you know its unique ID, use Shapes.Item ( UniqueIDString).

For example, you can use the following code:

Dim vsoShape As Visio.Shape 
Set vsoShape = Visio.ActivePage.Shapes.Item("{2287DC42-B167-11CE-88E9-0020AFDDD917}") 

Alternatively, you can use the following code, which adds the letter "U" before the string to identify it as a unique ID:

Dim vsoShape As Visio.Shape 
Set vsoShape = Visio.ActivePage.Shapes.Item("U{2287DC42-B167-11CE-88E9-0020AFDDD917}") 

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.