Visio Guy

Visio Discussions => Programming & Code => Topic started by: scott on September 16, 2014, 10:09:35 PM

Title: pg.index = n doesn't move page
Post by: scott on September 16, 2014, 10:09:35 PM
I've used code like this to relocate a page within a document many times:
dim pg as Visio.Page
set pg = ...
pg.index = n


where n is the desired new page position within the document. Normally works fine...

However, I have a document in which nothing happens when I issue pg.index = n. The event monitor looks normal
6154 > EnterScope  [1795;0;Reorder Pages;467164]
6155 | DocumentChanged TEST doc for Training and Resp Pages.vsd /pagesreordered  [/doc=1]
6156 < ExitScope  [1795;0;Reorder Pages;467164]


but the page doesn't move. I can move the page manually via the UI.

Is there a doc property or something else that could be preventing page reordering from working?

Thanks
Title: Re: pg.index = n doesn't move page
Post by: JohnGoldsmith on September 17, 2014, 07:21:42 AM
Hello Scott,

Page indices are 1 based so is it possible you're trying to use a zero index?

Otherwise, do you have a test document that shows the problem in more detail?

Best regards

John
Title: Re: pg.index = n doesn't move page
Post by: aledlund on September 17, 2014, 11:37:36 AM
This from John Marshall's site

Page Order: This code will change the order of a page.

To put the third page in front of the second page.

Activedocument.Pages.Item(3).Index = 2

al
Title: Re: pg.index = n doesn't move page
Post by: scott on September 17, 2014, 11:43:04 AM
Thanks, John and Al. The index value in question is in the teens -- attempting to move the page from approximately 19 to 14, for example.

I can't reproduce the problem outside a specific document at the moment, but I can't post the problem document publicly. Assuming I haven't missed a "don't allow page moves" property somewhere, I'll continue to experiment...
Title: Re: pg.index = n doesn't move page
Post by: scott on September 17, 2014, 02:04:58 PM
It turns out the problem has to do with the existence of a hidden page in the document. If I unhide the page, the page reorder operation works fine. Further experimentation required, but at least the problem is reproducible and there is a workaround.
Title: Re: pg.index = n doesn't move page
Post by: Jumpy on September 18, 2014, 06:35:57 AM
Could you elaborate on the workarround for later users that encounter the same problem?

Do you move all hidden pages to the end?
Title: Re: pg.index = n doesn't move page
Post by: scott on March 06, 2015, 12:01:05 AM
Sorry for the very long delay in responding...

In case anyone else has this problem, the workaround in VBA is fairly simple. To answer Jumpy's question: it does not require moving the hidden page(s) to the end. (In my case I couldn't have done that -- the reason for the existence of the hidden page is to act as a boundary between two sections of pages in the diagram.)

For VBA code to set a page index in order to move a page in a document that contains a hidden page, it is necessary to: