Link to home
Start Free TrialLog in
Avatar of brothertruffle880
brothertruffle880Flag for United States of America

asked on

Visio 2013 - executing VBA code after landing in a page

I have a 30 page Visio file and each time I navigate to a page 1, 3, 7, etc. I would like that page to change its view into FIT TO WINDOW.

How can I get this done?
SOLUTION
Avatar of Chris Roth
Chris Roth
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brothertruffle880

ASKER

Both solutions are equally useful, terse and brilliant.  
In a stupid design decision, EE only allows one BEST solution --which in this case is profoundly unjust.
Haha!
Scot:
Where do I place the code?
I put it in THIS DOCUMENT and nothing happened.
I put it in MODULE1 and the DIM statement appeared in Red.

Dim WithEvents Win1 As Visio.Window

Private Sub Document_DocumentOpened(ByVal doc As IVDocument)

    Set Win1 = ActiveWindow

End Sub

Private Sub Win1_WindowTurnedToPage(ByVal Window As IVWindow)

    Win1.Zoom = -1

End Sub 

Open in new window

Place the code in ThisDocument. Close the document and then open it again -- that will execute Document_DocumentOpened, which activates the ability to trap the turned-to-page event.

At this point, the code will be running but it won't look like it's doing anything unless you have pages that are zoomed in or out. So -- zoom way in or out on a page, change to another page and then change back to the first page -- it will be back to full page view.
Put code in ThisDocument
The attached file includes the code pasted from above.
Zoom-to-full-page-on-page-turn.vsd