Skip to content
  • Home
  • Work
  • About
  • Blog
  • Contact

Synchronizing page zoom 'WithEvents'

John Goldsmith's profile image

John Goldsmith

16 April 2008
  • Code

magnify

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):

XMLZoom

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...

ToolsMacrosMenu

...or uncomment the DocumentOpened and BeforeDocumentClose events to have the functionality work by default.

The Code

ZoomCode

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.

Microsoft MVP Logo

John has been a Microsoft MVP, in the award categories of Visio and M365, since 2008.

Visio Blogs

  • Bill Morein (via Wayback Machine)
  • Chris Castillo (via Wayback Machine)
  • Chris Hopkins (via Wayback Machine)
  • David Parker
  • Eric Rockey
  • Jesse Phillips-Mead
  • John Marshall
  • Michel LAPLANE (FR)
  • Nikolay Belyh
  • Saveen Reddy (via Wayback Machine)
  • Visio Guy
  • Visio [Product] Blog
  • Visio Insights (via Wayback Machine)

Visio Resources

  • Developing Microsoft Visio Solutions
  • Visio Stencils at ShapeSource
  • Microsoft Visio YouTube Playlist
  • Visio (Product site)
  • Office 2010 Engineering
  • Visio 2016 SDK (Download)
  • Visio JavaScript API reference
  • VisioMVPs.org
Contact

visualSignals ltd
31 Riverview Grove
London, W4 3QL
United Kingdom

+44 (0) 208 078 9120

Around the Web

Copyright © visualSignals ltd 2025

Mastodon