when parsing ConnectedShapes i am getting an error message "Invalid Sheet Identifier". to make the problem as simple as possible i cut and pasted this code from the online Visio VBA reference page (https://docs.microsoft.com/en-us/office/vba/api/visio.shape.connectedshapes). i got the same error with the sample code as i did with my code and got it at the same point in the code as highlighted, below.
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
please tell me that i'm doing something obvious and dumb.
For intCount = 1 To UBound(lngShapeIDs)
UBound is returning a value of -1 if there are no entries, 0 if there is one entry, and 1 if there are two entries. i tried starting Counter at 1 and got the same error.
the error is at 'ActivePage.Shapes(lngShapeIDs(intCount)).Name'.
Code works fine as proivided by the link. Are youi selecting a 2-D shape or a connecctor? The code wants the 2-D shape.
i am selecting a 2-D shape.
Microsoft Visio Standard 2016
Can you upload a simple example?
my original post has the verbatim example that i got from the Visio VBA documentation.
Yes, I got that. Since it works for me, having an upload from you might help track down why you're having a problem.
wrapperdude ... sorry about that. i'm relatively new to this site so don't have perfect insight into people's meanings.
Attached is my Visio with all of the extraneous stuff removed.
i still get the error.
i look forward to y'alls feedback.
I hereby declare you winner of Visio Bug award!
It seems many of Visio supplied shapes create the "Invalid" message. If you draw your own shapes there's no issue. If you use the vanilla, General, basic shapes, those are OK. But Flow chart shapes create error.
I'm not sure why these create an error. They just do.
There is another method to do this, which I finally remembered, dealing with glued shapes. This is will report both incoming and outgoing connections. The file has been updated to include the shapes you provided. Here's the code...
Public Sub GetGluedShapes()
'Use Shape.GluedShapes to get the shapes that are glued to a shape
Dim shp As Visio.Shape
Dim shpIDs() As Long
Dim i As Integer
Debug.Print "GluedShapes"
For Each shp In ActivePage.Shapes
If shp.OneD Then
Debug.Print shp.Name
shpIDs = shp.GluedShapes(visGluedShapesIncoming1D, "")
For i = 0 To UBound(shpIDs)
Debug.Print "Incoming 1D shapes"
Debug.Print ActivePage.Shapes.ItemFromID(shpIDs(i)).Name
Next
shpIDs = shp.GluedShapes(visGluedShapesOutgoing1D, "")
For i = 0 To UBound(shpIDs)
Debug.Print "Outgoing 1D shapes"
Debug.Print ActivePage.Shapes.ItemFromID(shpIDs(i)).Name
Next
shpIDs = shp.GluedShapes(visGluedShapesIncoming2D, "")
For i = 0 To UBound(shpIDs)
Debug.Print "Incoming 2D shapes"
Debug.Print ActivePage.Shapes.ItemFromID(shpIDs(i)).Name
Next
shpIDs = shp.GluedShapes(visGluedShapesOutgoing2D, "")
For i = 0 To UBound(shpIDs)
Debug.Print "Outgoing 2D shapes"
Debug.Print ActivePage.Shapes.ItemFromID(shpIDs(i)).Name
Next
End If
Debug.Print ""
Next
End Sub
i was unable to get any shapes to work using my code.
what i did get to work was to substitute ActiveDocument.Pages(I).Shapes.ItemFromID(ShapeIDs(Counter)) for ActiveDocument.Pages(I).Shapes(ShapeIDs(Counter))
thanks to all for your assistance.