Auto Fit-To-Page

J

jdfunk

Hello all,

I'm trying to create a macro that will set the zoom at Fit-to-Page every
time you click on a sheet. So far I've been able to get the macro to set the
zoom for all sheets at Fit-to-Page when the document is first opens up, but I
need the macro to continue working as you browse through the document. Here's
what I have so far. Does anyone have any suggestions as how to get the macro
to run every time I select a new tab?

Public Sub FitToPageAll()
Dim PageToIndex As Visio.Page
Dim curPage As Visio.Page

Set curPage = ActivePage

For Each PageToIndex In ActiveDocument.Pages
ActiveWindow.Page = ActiveDocument.Pages(PageToIndex.Index).Name
ActiveWindow.Zoom = -1
Next

ActiveWindow.Page = curPage
End Sub
 
A

Andy

Hello all,

I'm trying to create a macro that will set the zoom at Fit-to-Page every
time you click on a sheet.  So far I've been able to get the macro to set the
zoom for all sheets at Fit-to-Page when the document is first opens up, but I
need the macro to continue working as you browse through the document. Here's
what I have so far. Does anyone have any suggestions as how to get the macro
to run every time I select a new tab?

Public Sub FitToPageAll()
    Dim PageToIndex As Visio.Page
    Dim curPage As Visio.Page

    Set curPage = ActivePage

        For Each PageToIndex In ActiveDocument.Pages
        ActiveWindow.Page = ActiveDocument.Pages(PageToIndex.Index).Name
        ActiveWindow.Zoom = -1
    Next

    ActiveWindow.Page = curPage
End Sub

You will need to catch the WindowTurnedToPage event on the Visio
application.

Private WithEvents myVsoApp As Visio.Application

Private Sub Document_DocumentOpened( _
ByVal doc As IVDocument)


end sub
 
A

Andy

Hello all,

I'm trying to create a macro that will set the zoom at Fit-to-Page every
time you click on a sheet.  So far I've been able to get the macro to set the
zoom for all sheets at Fit-to-Page when the document is first opens up, but I
need the macro to continue working as you browse through the document. Here's
what I have so far. Does anyone have any suggestions as how to get the macro
to run every time I select a new tab?

Public Sub FitToPageAll()
    Dim PageToIndex As Visio.Page
    Dim curPage As Visio.Page

    Set curPage = ActivePage

        For Each PageToIndex In ActiveDocument.Pages
        ActiveWindow.Page = ActiveDocument.Pages(PageToIndex.Index).Name
        ActiveWindow.Zoom = -1
    Next

    ActiveWindow.Page = curPage
End Sub

You will need to catch the WindowTurnedToPage event on the Visio
application.

Private WithEvents myVsoApp As Visio.Application

Private Sub Document_DocumentOpened( _
ByVal doc As IVDocument)

set myVsoApp = doc.application

end sub

Private Sub myVsoApp_WindowTurnedToPage( _
ByVal Window As IVWindow)

window.zoom = -1
end sub
 
J

John Goldsmith_Visio_MVP

Hello JD,

Try pasting the following into your 'ThisDocument' class in the VBE:

Private WithEvents wdw As Window

Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
Set wdw = ActiveWindow
End Sub

Private Sub wdw_WindowTurnedToPage(ByVal Window As IVWindow)
Window.Zoom = -1
End Sub


If you're trying to programatically set zoom levels, you might also be
interested in this link:

http://visualsignals.typepad.co.uk/vislog/2008/04/synchronizing-p.html

Hope that helps.

Best regards

John


John Goldsmith (Visio MVP)
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top