Author Topic: Why does a =ThePage!ID() formula not give a Page ID() value?  (Read 650 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
Why does a =ThePage!ID() formula not give a Page ID() value?
« on: March 27, 2022, 02:29:47 AM »
Using the shape's ID() function in a formula works well and I use it frequently, however if I create a =ThePage!ID() formula I always get the value 0 (no matter on which page I run it, could be on a 20-page document on the 10th page).

Why doesn't this seemingly simple function work as expected?
Visio 2021 Professional

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3281
    • Paul Herber's website
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #1 on: March 27, 2022, 03:24:55 AM »
The ID of the first page in a document is 0. Add another page and get the ID of that.
Electronic and Electrical engineering, business and software stencils and applications for Visio -

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

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #2 on: March 27, 2022, 04:19:52 AM »
That's what I do Paul, if I try to get ThePage!ID() on the 10th page, I still get 0 as a result.
Visio 2021 Professional

Surrogate

  • Hero Member
  • *****
  • Posts: 1572
    • ShapeSheet™ Knowledge Base
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #3 on: March 27, 2022, 11:34:46 AM »
Each page is root shape with shape name Sheet.0

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #4 on: March 27, 2022, 01:11:57 PM »
There is no shapesheet fcn of that format.  There is VBA, but not as indicated.  To get shape ID, which is for fetching/documenting, see code example...
For shapesheet formula construction/syntax:  https://docs.microsoft.com/en-us/previous-versions/office/developer/office-xp/aa200961(v=office.10)

The debug.print lists three properties:  the name as displayed on tab, the order placement withing the pages, and the ID of the page.
Code
Sub Macro1()

    ActiveWindow.Page = Application.ActiveDocument.Pages.ItemU("Page-2")
    Set vPg = ActiveWindow.Page
    Debug.Print vPg.Name; vPg.Index; vPg.ID

End Sub
Visio 2019 Pro

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #5 on: March 27, 2022, 02:28:09 PM »
Thank you Wapperdude, yes with VBA it is no problem to get it.

The weird thing is that shapesheet autocomplete offers the ID() as an option when entering =TheDoc! or =ThePage! as a formula, but it just doesn't work.
Visio 2021 Professional

Surrogate

  • Hero Member
  • *****
  • Posts: 1572
    • ShapeSheet™ Knowledge Base
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #6 on: March 27, 2022, 02:46:19 PM »
There is no shapesheet fcn of that format.
You are right, but you can try
Quote from: Tumanov (aka Croc) in post #10921 (translated via Google Translate service)
if you write
=Pages[Page-1]!Sheet.0!Prop.Row_1, it will rename itself to ThePage. Because ThePage is also a shape
« Last Edit: March 28, 2022, 02:30:40 AM by Surrogate »

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #7 on: March 28, 2022, 04:41:02 AM »
Surrogate thank you but specifically I am trying to get the ID() function to work on the page, getting a User or Prop field works well. Though thinking about it, I could also put the Page ID() in a page User field then read that field! Same for the document. Doh!
Visio 2021 Professional

Surrogate

  • Hero Member
  • *****
  • Posts: 1572
    • ShapeSheet™ Knowledge Base
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #8 on: March 28, 2022, 05:59:22 AM »
huh ! what useful information Page.ID contains ?

vojo

  • Hero Member
  • *****
  • Posts: 1670
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #9 on: March 28, 2022, 08:35:01 AM »
which of N pages involved?
I may be an out layer, but typically have several drawing pages as well as several background pages.
So if I were trying to target some shape on some page, page ID might be helpful to me

Surrogate

  • Hero Member
  • *****
  • Posts: 1572
    • ShapeSheet™ Knowledge Base
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #10 on: March 28, 2022, 09:00:17 AM »
The ID of the first page in a document is 0. Add another page and get the ID of that.
The second page ID = 4, and so on in order. If subsequently one of the pages will be deleted, its ID will be excluded from the list...

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #11 on: March 28, 2022, 09:39:48 AM »
Well, outlayer#2 here.  Why ID and not Name or Index?  The index is a very hidden value, so, for user referencing not most useful.  Also, for debugging, there is no intuitive way to remember, at a much later date, what a formula is doing. 

As for page names & index numbers,  these are very obvious, but, present dilemma of being easily changed.  In the case of names, a most simple macro can be used to keep name and names synchronized.  An, already suggested alternative, is to create a User cell with a meaningful descriptive identifier.   Page ID is the most mutation resistant identifier, but also the least informative..  Guess that was 1.5 cents worth of comment.  🤔😲
Visio 2019 Pro

Visisthebest

  • Hero Member
  • *****
  • Posts: 637
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #12 on: March 28, 2022, 10:14:29 AM »
Using the Page ID because I need a reference to the page that is guaranteed to be unique, I assumed pages can have identical names and users can cause issues by renaming pages.
Visio 2021 Professional

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4374
  • Ideas Visio-lized into solutions
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #13 on: March 28, 2022, 10:37:21 AM »
That seemed like the rationale.

Certainly, page name and indexing are easily manipulated.  But, if not mistaken, names requires very deliberate effort.  It is not something the casual user would change.  I believe it can only be changed by code.
Visio 2019 Pro

Surrogate

  • Hero Member
  • *****
  • Posts: 1572
    • ShapeSheet™ Knowledge Base
Re: Why does a =ThePage!ID() formula not give a Page ID() value?
« Reply #14 on: March 28, 2022, 12:03:20 PM »
Page ID is the most mutation resistant identifier, but also the least informative..  Guess that was 1.5 cents worth of comment.  🤔😲
I agree with this! Hope my comment costs about 7.40 roubles  ;)
That seemed like the rationale.

Certainly, page name and indexing are easily manipulated.  But, if not mistaken, names requires very deliberate effort.  It is not something the casual user would change.  I believe it can only be changed by code.
In this case you need create list for storage pagenames  and their indexes. I think it is possible with VBA.
« Last Edit: March 28, 2022, 12:57:30 PM by Surrogate »