MNJ
MNJ

Reputation: 1

"Shape.ConnectedShapes method (Visio)" example from Microsoft site give "Invalid Sheet Identifier" error

I will start by saying I am not an experienced VBA programmer. In trying some VBA code in Visio, I tried the outgoing connector example provided with the topic "[Shape.ConnectedShapes method (Visio)][1]". When I run the code with no changes on a very simple Visio diagram (start/stop shape -> process shape -> start/stop shape) I get a "Invalid Sheet Identifier" error. In debugging I have found that it works on start/stop shapes with zero or one outbound connectors, but does not work on process shapes with one or more outbound connectors. The error occurs when executing the line "Debug.Print ActivePage.Shapes(lngShapeIDs(intCount)).Name". Any ideas on what is wrong? The code from the Microsoft site is:

'From the Microsoft site as the link posted above Public Sub ConnectedShapes_Outgoing_Example() ' Get the shapes that are connected to the selected shape ' by outgoing connectors. Dim vsoShape As Visio.Shape Dim lngShapeIDs() As Long Dim intCount As Integer

If ActiveWindow.Selection.Count = 0 Then
    MsgBox ("Please select a shape that has connections")
    Exit Sub
Else
    Set vsoShape = ActiveWindow.Selection(1)
End If

lngShapeIDs = vsoShape.ConnectedShapes _
  (visConnectedShapesOutgoingNodes, "")
Debug.Print "Shapes at the end of outgoing connectors:"
For intCount = 0 To UBound(lngShapeIDs)
    Debug.Print ActivePage.Shapes(lngShapeIDs(intCount)).Name   'Where the error occurs
Next

End Sub

Upvotes: 0

Views: 576

Answers (1)

Алексей Р
Алексей Р

Reputation: 7627

Try to use

Debug.Print ActivePage.Shapes.ItemFromID(lngShapeIDs(intCount)).Name

Indexes in the ActivePage.Shapes collection range from 1 to ActivePage.Shapes.Count. Shape IDs are not the same as the number of shapes in the collection. So get the shape by identifier correctly using Shapes.ItemFromID

Upvotes: 2

Related Questions