Visio Guy

Visio Discussions => Programming & Code => Topic started by: stanbriggs on November 21, 2021, 09:40:27 PM

Title: Invalid Sheet Identifier
Post by: stanbriggs on November 21, 2021, 09:40:27 PM
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.
Title: Re: Invalid Sheet Identifier
Post by: Paul Herber on November 21, 2021, 10:12:49 PM
For intCount = 1 To UBound(lngShapeIDs)
Title: Re: Invalid Sheet Identifier
Post by: stanbriggs on November 22, 2021, 12:52:59 PM
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'.
Title: Re: Invalid Sheet Identifier
Post by: wapperdude on November 22, 2021, 03:12:11 PM
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.
Title: Re: Invalid Sheet Identifier
Post by: stanbriggs on November 22, 2021, 03:16:50 PM
i am selecting a 2-D shape.
Microsoft Visio Standard 2016
Title: Re: Invalid Sheet Identifier
Post by: wapperdude on November 22, 2021, 03:58:45 PM
Can you upload a simple  example?
Title: Re: Invalid Sheet Identifier
Post by: stanbriggs on November 22, 2021, 06:17:36 PM
my original post has the verbatim example that i got from the Visio VBA documentation.
Title: Re: Invalid Sheet Identifier
Post by: wapperdude on November 22, 2021, 06:32:07 PM
Yes, I got that.  Since it works for me, having an upload from you might help track down why you're having a problem.
Title: Re: Invalid Sheet Identifier
Post by: stanbriggs on November 22, 2021, 06:53:55 PM
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.
Title: Re: Invalid Sheet Identifier
Post by: wapperdude on November 22, 2021, 10:39:14 PM
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.
Title: Re: Invalid Sheet Identifier
Post by: wapperdude on November 23, 2021, 12:10:26 AM
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
Title: Re: Invalid Sheet Identifier
Post by: stanbriggs on November 23, 2021, 04:31:17 PM
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.