Home > database >  Invalid Sheet Identifier when trying to get shapes connected to another shape
Invalid Sheet Identifier when trying to get shapes connected to another shape

Time:01-20

I took this code directly from the VBA documentation from Microsoft, I am trying to select a shape then iterate through outgoing connected shapes.

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
    Next
End Sub

lngShapeIDs array gives me one item with an ID of 1077.

Then this:

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

...gives me an "Invalid Sheet Identifier" error, as if the ID doesn't exist.

CodePudding user response:

The Shapes collection takes an index rather than an ID.

You need Shapes.ItemFromId

  • Related