Visio Guy

Visio Discussions => Programming & Code => Topic started by: perry59 on February 19, 2015, 08:49:35 PM

Title: when changing pages
Post by: perry59 on February 19, 2015, 08:49:35 PM
say you have a document with page 1, page 2, etc.
is there not an event that's triggered when going to different pages in the document?
I'd like to catch that event and add code to do a "zoom all". getting SO sick of going to various pages and finding them zoomed into some small area of the drawing >:(
Title: Re: when changing pages
Post by: wapperdude on February 19, 2015, 09:37:13 PM
From macro recorder (with minor edit):

Sub ZoomOutPage()

    ActiveWindow.ViewFit = visFitPage

End Sub


Wapperdude
Title: Re: when changing pages
Post by: perry59 on February 20, 2015, 12:46:15 AM
Thanks Wapper, but I already had that part.
I want that code to run whenever I (manually) change the active page.
so I'm looking for an event to catch

Perry
Title: Re: when changing pages
Post by: wapperdude on February 20, 2015, 01:00:21 AM
Must read more carefully.  Must improve memory recall, too.

Unfortunately, Visio does not have an exit page event.  I don't think that's changed with the newer releases, but, I could be wrong.

Anyway, found this article, better to let it explain itself:  http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Visio/Q_28130978.html (http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Visio/Q_28130978.html)

Wapperdude
Title: Re: when changing pages
Post by: perry59 on February 20, 2015, 04:04:48 AM
Must read more carefully.  Must improve memory recall, too.
when you get the process down, please share!!

Unfortunately, Visio does not have an exit page event.  I don't think that's changed with the newer releases, but, I could be wrong.

I was afraid of that
Anyway, found this article, better to let it explain itself:  http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Visio/Q_28130978.html

couldn't read the article

looks like I'll be hitting control W endlessly :(

why doesn't this forum have a "quote" feature?
Title: Re: when changing pages
Post by: Yacine on February 20, 2015, 05:45:35 AM
would CTRL+w help?
Title: Re: when changing pages
Post by: Paul Herber on February 20, 2015, 07:18:57 AM
Quote from: perry59 on February 20, 2015, 04:04:48 AM
why doesn't this forum have a "quote" feature?

Title: Re: when changing pages
Post by: AndyW on February 20, 2015, 08:55:33 AM
You can use the WindowTurnedToPage event on the application or window.
Title: Re: when changing pages
Post by: perry59 on February 20, 2015, 07:49:55 PM
Quote from: Paul Herber on February 20, 2015, 07:18:57 AM
Quote from: perry59 on February 20, 2015, 04:04:48 AM
why doesn't this forum have a "quote" feature?

Must use those glasses  ::)
Title: Re: when changing pages
Post by: perry59 on February 20, 2015, 07:50:55 PM
Quote from: AndyW on February 20, 2015, 08:55:33 AM
You can use the WindowTurnedToPage event on the application or window.

I'll check into that, thanks
Title: Re: when changing pages
Post by: perry59 on February 20, 2015, 08:27:27 PM
I tried the code below, but get an error on the first line (withevents).
Am I missing a reference or something?

thanks

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
Title: Re: when changing pages
Post by: daihashi on February 22, 2015, 11:11:17 PM
Quote from: AndyW on February 20, 2015, 08:55:33 AM
You can use the WindowTurnedToPage event on the application or window.

Yes, I use this same event trigger to pull up custom dashboards when a person moves from page to page. I also use ViewChanged to detect the zoom level, and my documents use that as a multiplier to thicken the lines if you are zoomed fairly far out (visio 2013 has a glitch where lines become pencil thin at certain zoom levels).

What the OP needs to do is to create an event handler. The MSDN has a pretty good walkthrough on how to accomplish this.
Title: Re: when changing pages
Post by: daihashi on February 22, 2015, 11:29:05 PM
Quote from: perry59 on February 20, 2015, 08:27:27 PM
I tried the code below, but get an error on the first line (withevents).
Am I missing a reference or something?

thanks

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

I suspect you're missing a few things.

Option Explicit
Public WithEvents wnd2 As Visio.Window


Private Sub Document_DocumentOpened(ByVal doc As IVDocument)

Set wnd2 = ActiveWindow

End Sub

Private Sub wnd2_WindowTurnedToPage(ByVal Window As IVWindow)

<Insert whatever code you want>

End sub



Alternatively; you could use the add advise method.
Implements Visio.IVisEventProc

Private Const visEvtAdd% = &H8000

Private Function IVisEventProc_VisEventProc( _
    ByVal nEventCode As Integer, _
    ByVal pSourceObj As Object, _
    ByVal nEventID As Long, _
    ByVal nEventSeqNum As Long, _
    ByVal pSubjectObj As Object, _
    ByVal vMoreInfo As Variant) As Variant

    Dim strMessage As String

If nEventCode = (visEvtAdd + visEvtShape) Then
    DoEvents
ElseIf Not nEventCode = visEvtCodeWinPageTurn Then
    DoEvents
ElseIf nEventCode = visEvtCodeEnterScope Then
    DoEvents
ElseIf nEventCode = visEvtMod + visEvtCell Then
    DoEvents
ElseIf nEventCode = visEvtMod + visEvtPage Then
    ThisDocument.pagenamed
ElseIf nEventCode = visEvtCodeBefSelDel Then
    ThisDocument.vshapes
ElseIf nEventCode = visEvtCodeQueryCancelSelDel Then
    ThisDocument.vshapes
ElseIf visEvtAdd + visEvtPage Then
    ThisDocument.update_activepageID
ElseIf nEventCode = visEvtAdd + visEvtWindow Then

End If
End Function

Private mEventSink As clsEventSink
Dim vsoDocumentEvents As Visio.EventList
Dim vsoDocumentSavedEvent As Visio.Event
Dim vsoPageAddedEvent As Visio.Event
Dim vsoShapesDeletedEvent As Visio.Event
Dim vsoShapesAddedEvent As Visio.Event
Dim vsoCellChangedEvent As Visio.Event
Dim vsoWinPageTurnEvent As Visio.Event
Dim vsoPageChangedEvent As Visio.Event
Dim vsoSelectionDeletedEvent As Visio.Event
Dim vsoQueryCancelSelDelEvent As Visio.Event
Dim vsoWindowOpenedEvent As Visio.Event
Private Const visEvtAdd% = &H8000

Public Sub CreateEventObjects()

    Set mEventSink = New clsEventSink

    Set vsoDocumentEvents = ActiveDocument.EventList

    Set vsoDocumentSavedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtCodeDocSave, mEventSink, "", "")

    Set vsoPageAddedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtAdd + visEvtPage, mEventSink, "", "")

    Set vsoPageChangedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtMod + visEvtPage, mEventSink, "", "")

    Set vsoQueryCancelSelDelEvent = vsoDocumentEvents.AddAdvise( _
        visEvtCodeQueryCancelSelDel, mEventSink, "", "")
    Set vsoSelectionDeletedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtCodeBefSelDel, mEventSink, "", "")
     
    Set vsoShapesAddedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtAdd + visEvtShape, mEventSink, "", "")
     
    Set vsoCellChangedEvent = vsoDocumentEvents.AddAdvise( _
     visEvtMod + visEvtCell, mEventSink, "", "")
     
    Set vsoWinPageTurnEvent = vsoDocumentEvents.AddAdvise( _
     visEvtCodeWinPageTurn, mEventSink, "", "")
     
     Set vsoWindowOpenedEvent = vsoDocumentEvents.AddAdvise( _
        visEvtAdd + visEvtWindow, , mEventSink, "", "")

End Sub



I hope that helps
Title: Re: when changing pages
Post by: perry59 on March 01, 2015, 05:54:05 AM
Thanks daihashi for the detailed explanation!
I'll try that as soon as I can, been SUPER busy lately!