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 >:(
From macro recorder (with minor edit):
Sub ZoomOutPage()
ActiveWindow.ViewFit = visFitPage
End Sub
Wapperdude
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
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
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?
would CTRL+w help?
You can use the WindowTurnedToPage event on the application or window.
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
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
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.
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.
- First, I bet you're missing a public variable to reference the Visio.Window Object. You will need something like this in the declarations section:
Option Explicit
Public WithEvents wnd2 As Visio.Window
- Then you need to set the variable somehow. I use the DocumentOpened event to automatically set these objects when the document is opened:
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
Set wnd2 = ActiveWindow
End Sub
- Then you can use the defined object to create the routine for WindowTurnedtoPage:
Private Sub wnd2_WindowTurnedToPage(ByVal Window As IVWindow)
<Insert whatever code you want>
End sub
Alternatively; you could use the add advise method.
- First you will want to create a Class module to act as the Event Sink
- Inside the Class Module you will want the following code; you will need to call out each event type that you wish to capture:
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
- Then you need to define variables for these events in the declarations section of "ThisDocument", here are a few to get you started... note that the constant "visEvtAdd%" is necessary and not optional:
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
- Then you will want to define all of the event variables. Again, I do this from document open (well I used to.. I no longer use the add advise method). I create the following routine, and then call to it from document open:
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
Thanks daihashi for the detailed explanation!
I'll try that as soon as I can, been SUPER busy lately!