News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Page Number References

Started by stevray, April 22, 2010, 07:08:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stevray

Is there any way of referencing a page number such that it remains correct even as pages are added, deleted, or reordered.  In particular, I want to add a text field that says something like "See page 12" in such a way that it will automatically change to "See page 13" if I add a new page before the existing page 12.

Yacine

#1
Hi Stevray,
like for regular shapes, visio updates automaticaly the formulas refering to shape names, regardless how many pages you insert or delete. Even renaming the referenced page does not affect the functionality.
Yacine

scott

The trick you're looking for, I think, is to embed the Pagename() function in a cell on the target page. Whether you add or delete pages, or change the name of the target page, the shapesheet cell will always contain the target page's name. And you can refer to the cell containing the page name function from anywhere else in the drawing.

In the attached drawing, the target page contains a user field called User.TargetPage with a value of PAGENAME()

The text box on page one contains a field that references User.TargetPage on the target page. The syntax is a bit bizarre
Pages[Page-3]!ThePage!User.TargetPage
but it gets the job done.

For good measure I also gave the text box on Page-1 a hyperlink to the target page. The hyperlink uses the same syntax for the link and the description so both will always be correct.

stevray

It's a little more complicated.  The "Page-3" in the expression Pages[Page-3] is the universal name (NameU) of the target page, not the local or displayed name.  These are not always the same and you do not have direct control over NameU; in fact, short of writing a little code, it is not easy to get NameU.

In my case, I have a template that includes a page with a name "Location Map" but that page has the universal name "Location" (I assume that at one time, I named it that but then subsequently changed it).  If I now enter the formula Pages[Location Map], I get the immensely informative error message "Error in Formula"; if I use Pages[Location] it works but I have to either remember that the page "Location Map" actually has a universal name "Location" or I have to write code to get the universal name.

There must be a better way.  Any ideas would be welcome.

scott

#4
You are correct about the Name vs. NameU issue for the page name. However, if you create the Pages[xxx] formula before a page has been renamed, thereby capturing its NameU, the formula will always evaluate correctly regardless of subsequent name changes.

If you have already renamed the page, then you do have to go through the extra step of finding the NameU value via code or something like the page report in Paul Herber's Visio Super Utilities. Armed with the NameU value, Pages[] will always evaluate correctly.

BTW, Paul's page report, on noticing a discrepancy between a page's Name and NameU. even offers to set NameU to the Name value, which simplifies insertion of the Pages[] formula (see screen shot below).

Paul Herber

I'm not 100% happy with the words shown in that dialog box. Why is it only when one sees ones work like this that these things stand out like a sore thumb?

Electronic and Electrical engineering, business and software stencils for Visio -

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

scott

I know what you mean, Paul. I've run across phrasing or word choices that have been in our product for years that suddenly jump out and scream at me!

Paul Herber

Here is a screenshot from the (now updated) utilities (but not on the website yet!) showing the dangers of having different Name and NameU for your pages and shapes.

Electronic and Electrical engineering, business and software stencils for Visio -

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

stevray

I wrote a little addon in VB.Net (took me about an hour) that cycles through all of the foreground pages in the active document. 

If the universal name is not equal to the local name, corrects it.

If the page sheet does not currently have a cell named User.PageName, it creates the cell and puts the PAGENAME() formula into it.

If the page sheet does not currently have a cell name User.PageNumber, it creates it and puts PAGENUMBER() into it.

You can then easily create text references to other page names and numbers the custom formua

Pages['page-name']!ThePage!User.PageName or as Pages['page-name']!ThePage!User.PageNumber where 'page-name' is the current local name of the target page.

If anyone is interested, I can post the code and/or executable.


Yacine

Of course, we would be interested, but that would spoil Paul's business.
Some guys here earn their money with visio.  ;D ;D ;D
Yacine

Paul Herber

I don't mind if someone wants to post their own code!
Electronic and Electrical engineering, business and software stencils for Visio -

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

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 329 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1189KB.
Tokens: post-login.
Cache hits: 13: 0.00199s for 26,745 bytes (show)
Cache misses: 2: (show)
Queries used: 15.

[Show Queries]