Jump to the first page when its name is not known

Started by Hey Ken, April 11, 2018, 05:12:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hey Ken

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

Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

Hey Ken


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

   - Ken
Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

Yacine

Right, I spent over an hour on it  without success.
Yacine

metuemre

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,

Croc

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.

Hey Ken


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

Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

Hey Ken

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 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
Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com