Link to home
Start Free TrialLog in
Avatar of Dimitrie Vatra
Dimitrie Vatra

asked on

Change the Active Page in visio

Hi!
 i'm trying to change between visio pages from code. That means i need to set the VisioApplication.ActivePage, but it is readonly. So i'm trying to set the VisioApplication.ActiveWindow.Page.
All good, but when i try that, i get a runtime exception 'Invalid container identifier.'. Anything i tried didn't work. I know that VisioApplication.ActiveWindow.Page is a dynamic variable in c#. But i still don't know how to handle this exception. My code is :

Globals.ThisAddIn.Application.ActiveWindow.Page = Globals.ThisAddIn.Application.ActiveDocument.Pages[0];

I need to mention that it is a Visio AddIn project.
Please, i'm trying to fix this out for 2 weeks, and nothing worked. Any help will be really apreciated.
Thanks!
Dimitrie
Avatar of Dimitrie Vatra
Dimitrie Vatra

ASKER

This may looks stupid, but i found the answer, and i'm writting it for anyone to see this:
Globals.ThisAddIn.Application.ActiveWindow.Page = Globals.ThisAddIn.Application.ActiveDocument.Pages.ItemFromID[MyPageID];
Avatar of Scott Helmers
Your line of code above will work, as you've discovered, but it isn't the only way.

ActiveWindow.Page is the correct object and you change active pages from code by equating it to a page name or page reference. For example, assuming that "Page-1" is the first page in the document, all three of these will switch to that page:

    ActiveWindow.Page = "Page-1"
   
    ActiveWindow.Page = ActiveDocument.Pages(1)

    ActiveWindow.Page = ActiveDocument.Pages("Page-1")

BTW, refer to the very first sample on this page of VBA code samples for Visio.
Dimitrie -- when you have a moment, please close the question either by selecting your answer by itself or including mine by clicking "Assisted Solution".
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.