Author Topic: Invalid Sheet Identifier  (Read 1135 times)

0 Members and 1 Guest are viewing this topic.

stanbriggs

  • Jr. Member
  • **
  • Posts: 15
Invalid Sheet Identifier
« on: November 21, 2021, 04: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.

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3107
    • Paul Herber's website
Re: Invalid Sheet Identifier
« Reply #1 on: November 21, 2021, 05:12:49 PM »
For intCount = 1 To UBound(lngShapeIDs)
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

stanbriggs

  • Jr. Member
  • **
  • Posts: 15
Re: Invalid Sheet Identifier
« Reply #2 on: November 22, 2021, 07:52:59 AM »
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'.

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4092
  • Ideas Visio-lized into solutions
Re: Invalid Sheet Identifier
« Reply #3 on: November 22, 2021, 10:12:11 AM »
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.
Visio 2019 Pro

stanbriggs

  • Jr. Member
  • **
  • Posts: 15
Re: Invalid Sheet Identifier
« Reply #4 on: November 22, 2021, 10:16:50 AM »
i am selecting a 2-D shape.
Microsoft Visio Standard 2016

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4092
  • Ideas Visio-lized into solutions
Re: Invalid Sheet Identifier
« Reply #5 on: November 22, 2021, 10:58:45 AM »
Can you upload a simple  example?
Visio 2019 Pro

stanbriggs

  • Jr. Member
  • **
  • Posts: 15
Re: Invalid Sheet Identifier
« Reply #6 on: November 22, 2021, 01:17:36 PM »
my original post has the verbatim example that i got from the Visio VBA documentation.

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4092
  • Ideas Visio-lized into solutions
Re: Invalid Sheet Identifier
« Reply #7 on: November 22, 2021, 01: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.
Visio 2019 Pro

stanbriggs

  • Jr. Member
  • **
  • Posts: 15
Re: Invalid Sheet Identifier
« Reply #8 on: November 22, 2021, 01: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.

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4092
  • Ideas Visio-lized into solutions
Re: Invalid Sheet Identifier
« Reply #9 on: November 22, 2021, 05: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.
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4092
  • Ideas Visio-lized into solutions
Re: Invalid Sheet Identifier
« Reply #10 on: November 22, 2021, 07:10:26 PM »
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...
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
« Last Edit: November 22, 2021, 07:20:33 PM by wapperdude »
Visio 2019 Pro

stanbriggs

  • Jr. Member
  • **
  • Posts: 15
Re: Invalid Sheet Identifier
« Reply #11 on: November 23, 2021, 11:31:17 AM »
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.