Weird behavior of Page ID() function on the Shapesheet

Started by Visisthebest, December 27, 2020, 01:25:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visisthebest

Am I missing something? This behavior of the page's shapesheet ID() function is plain weird.

The behavior observed is with Visio Plan 2 desktop updated to latest stable release (I guess comparable with Visio 2019):

I start a new empty Visio file and add 2 extra pages. I open the basic shapes stencil and use those shapes for testing.

On the third page I try to read the page ID with the shapesheet page ID() function, either in a User field in the page shapesheet or directly on a shape with ThePage!ID().

The ID() is shown as 0 though, even though if I use the VBA below I can see the page ID is 5!

I am puzzled why I get 0 and not the correct page ID of the third page. If I use the name function on the shapesheet I do get the correct page name.

Is this an issue/bug in Visio or is there an underlying reason for this behavior? It sure is weird and unexpected, how then to get the actual page ID in the shapesheet?

Thank you for your help!

Code from Microsoft:


Public Sub Pages_Example()
 
    Dim intCounter As Integer
    Dim vsoDocument As Visio.Document 
    Dim vsoPages As Visio.Pages 

    'Get the Pages collection for the active document. 
    Set vsoPages = ActiveDocument.Pages
 
    Debug.Print "Page names for document: "; ActiveDocument.Name
 
    'Iterate through the pages and print the page name 
    'in the Immediate window. 
    For intCounter = 1 To vsoPages.Count 
        Debug.Print " "; vsoPages.Item(intCounter).Name; "ID: "; CStr(vsoPages.Item(intCounter).ID)
    Next intCounter 

End Sub


I updated the code, forgot I made a small change to get the Page ID's to the MS example:
        Debug.Print " "; vsoPages.Item(intCounter).Name; "ID: "; CStr(vsoPages.Item(intCounter).ID)
Visio 2021 Professional

Paul Herber

#1
Your code is was looking at the page index, not the ID.
The ID (within the shapesheet) is only valid for a shape, not a page.

https://docs.microsoft.com/en-us/office/vba/api/visio.shape.id
Electronic and Electrical engineering, business and software stencils for Visio -

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

Visisthebest

So the ID() function on a page is something different from the ID() function on a page? 🤯

Thank you Paul for clarifying very confusing, is there a way to get the page ID with a shapesheet function?
Visio 2021 Professional

wapperdude

Actually, I'm not sure Pages have ID numbers in the sense that your thinking.  Within a shape's shapesheet, there are 3 page functions, pagecount, pagename, and pagenumber. 
Visio 2019 Pro

Visisthebest

In VBA they do https://docs.microsoft.com/en-us/office/vba/api/visio.page.id
and because there is a shapesheet ID() function I sure hoped I could use it directly on the shapesheet as well.

If anyone has a tip...super!
Visio 2021 Professional

wapperdude

Visio 2019 Pro

wapperdude

#6
Here's code to show various page info, including unique ID.

Sub Pages_Example()
' Macro itertes thru all pages in file.  Prints the page name, ID, and Unique ID.
' Thanks to Visio Guy for info on Page Unique ID.
 
    Dim intCounter As Integer
    Dim vsoDocument As Visio.Document
    Dim vsoPages As Visio.Pages
    Dim vPg As Visio.Page

'Get the Pages collection for the active document.
    Set vsoPages = ActiveDocument.Pages
 
    Debug.Print "Page info in document: "; ActiveDocument.Name
 
'Iterate through the pages and print the Page count, page name, page ID in the Immediate window.
    For intCounter = 1 To vsoPages.Count
        ActiveWindow.Page = ThisDocument.Pages(intCounter).Name
        Set vPg = ThisDocument.Pages.Item(intCounter)
        Debug.Print intCounter; " "; vPg; vPg.ID; vPg.PageSheet.UniqueID(Visio.VisUniqueIDArgs.visGetOrMakeGUID)
    Next intCounter

End Sub
Visio 2019 Pro