Visio Guy

Visio Discussions => Programming & Code => Topic started by: Hey Ken on April 11, 2018, 05:12:16 PM

Title: Jump to the first page when its name is not known
Post by: Hey Ken on April 11, 2018, 05:12:16 PM
Folks:

    Quick question: I want to use shapesheet functionality to jump to the first page, either as a double click or right-click action.  The complication is that I don't necessarily know the name of the first page.  It's trivial to do in VBA...



ActiveWindow.Page = ActiveDocument.Pages.ItemU(1)



   ...but how do I do it on the shapesheet?  GOTOPAGE requires that you know the name.  Ditto for Pages[1]!ThePage!User.PageName.  Further complicating things, I want to do it from a background page, so I can't use a hyperlink--not that it would work either.

    Thanks in advance,

    - Ken

Title: Re: Jump to the first page when its name is not known
Post by: Hey Ken on April 19, 2018, 03:45:45 PM

   Hmmm... 42 views, 0 replies.  I guess it's not possible.  Time for Plan B (as in VBA).

   - Ken
Title: Re: Jump to the first page when its name is not known
Post by: Yacine on April 20, 2018, 05:30:25 AM
Right, I spent over an hour on it  without success.
Title: Re: Jump to the first page when its name is not known
Post by: metuemre on April 20, 2018, 06:57:49 AM
I got a partial solution that requires to know the name of the first page only once. Please check the attached file.

Assuming that first page is named as "Page-1" at the beginning. The formula "=Pages[Page-1]!ThePage!PAGENAME()" returns the name of "Page-1". The beauty of this formula is that it updates itself if "Page-1" is renamed to something else. So the formula  "=GOTOPAGE(Pages[Page-1]!ThePage!PAGENAME())" inside EventDblClick cell will always take you to the first page.

Regards,
Title: Re: Jump to the first page when its name is not known
Post by: Croc on April 20, 2018, 10:27:32 AM
There is one more thought ...
If you force all pages to transfer their names to a document, then perhaps this will help solve the problem.
Look at the picture.
Several User Cells are created in the document.
On each page there is a shape that transfers the value of PageName to the user.Row_ + i cell of the document, where i = PageNumber. That is, it creates a table of contents for the document.
Title: Re: Jump to the first page when its name is not known
Post by: Hey Ken on April 20, 2018, 11:49:58 AM

Metuemre:

   That did it!  Your solution fit the use case perfectly. 

   You see, I distribute a template file with several pages, and some of those pages have a link to jump back to the first page.  My justified concern is that people will change the name of the first page (with me being one of the most egregious offenders) and break things.  GOTOPAGE(Page-1) breaks.  But your solution never breaks, even if you move things around or create a new first page.  Visio remembers the page by some internal name apparently not available to us mere humans.  Nice.


Croc:

   An interesting approach, but not nearly as simple.  But at least it has the decency to be understandable.  On the other hand, Metuemre's solution could be maddening when someone sees it jumps to a page that does not exist.


Yacine:

   Thanks muchly for the attempt, as always.


All:

   Until next time,

   - Ken

Title: Re: Jump to the first page when its name is not known
Post by: Hey Ken on March 25, 2019, 12:54:01 PM
Quote from: Hey Ken on April 20, 2018, 11:49:58 AM

   But your solution never breaks, even if you move things around or create a new first page.  Visio remembers the page by some internal name apparently not available to us mere humans.  Nice.


   Famous last words, as they say, because FYI the solution does break under certain circumstances.  For some odd reason, if you put the formula "=Pages[Page-1]!ThePage!PAGENAME()" into the document shapesheet, Visio blows up with a 318 error whenever you press ctrl-C (using 2013 professional).  No idea why.  Fortunately, Surrogate wrote a short macro (http://visguy.com/vgforum/index.php?topic=5953.msg23994#msg23994) to prevent the errors from occurring, albeit at some cost.  But having a solution is better than not having one, and I'm not surprised to find the solution here on this forum -- written five years ago!

   - Ken