How do you synchronize the page zoom level and window view across all pages in a Visio document? This was a recent (paraphrased) question in the newsgroups and caught my eye as an interesting problem...
Standard behaviour
Normal zoom behaviour in Visio is set on a page by page basis. Each page has a set of properties (ViewScale, ViewCenterX and ViewCenterY) that record the respective values and you can see this if you save your document in .vdx format and view the XML. Here's a screenshot of the relevant section using XML Notepad showing Page-1's zoom level set at 75% (0.75):
Now, you might think you could just set these all to a central source and 'voila', you'd be synchronized. Unfortunately these aren't normal properties. You can't access them via either the page's ShapeSheet or via straight code, so we need to look for another route.
In answer to the original newsgroup question Paul Herber, of Sandrila, very sensibly suggested an application-wide add-on, however if you're just looking for a document level solution the following is one possibility.
Waiting for PageTurn event
The trick is here is to listen to the BeforeWindowPageTurn event of the Window object to get the zoom level and window view dimensions for the current page before you leave it.
Having got these details, and saved them in variables, you can then set them for the new page using the WindowTurnedToPage event.
To use the code, just paste it into the ThisDocument module in the VBE (see the 'Just for starters' post if this makes no sense to you) and you can then either call it from the Tools / Macro menu...
...or uncomment the DocumentOpened and BeforeDocumentClose events to have the functionality work by default.
The Code
Don't forget layers
Of course all of the above might not be necessary if you find that layers can do the job instead. In fact layers will likely provide a better answer for most situations, but if you do find you need to synchronize pages together then the above is a fairly simple method of doing so.
Further reading
- Assigning Shapes and Masters to Layers (DVS)
- Toggling layers on and off (David Parker - bVisual)
- Writing Code Behind Events (DVS)
- Window.BeforeWindowPageTurn Event (Visio 2007 SDK)
- Run VBA Code When Documents Open (VisGuy.com)
You can download an example document (Download SynchronizingZoomWithEvents.vsd), which contains a complete version of the above code.