Open the Visual Basic Edit and place this code behind the "ThisDocument" object:
|
Dim refreshActive As Boolean
Sub StartAutoRefresh()
Dim dataRecordSetObj As DataRecordset
Dim PauseTime, Start
PauseTime = 10 ' Set duration.
If MsgBox("Do you want to start auto-refresh?", vbYesNo) = vbYes Then
refreshActive = True
While refreshActive
For Each dataRecordSetObj In Me.DataRecordsets
dataRecordSetObj.Refresh
DoEvents ' Yield to other processes.
Next dataRecordSetObj
Start = Timer ' Set start time.
Do While (Timer < Start + PauseTime) And refreshActive
DoEvents ' Yield to other processes.
Loop
Wend
End If
End Sub
Sub EndAutoRefresh()
refreshActive = False
End Sub
Private Sub Document_BeforeDocumentClose(ByVal doc As IVDocument)
EndAutoRefresh
End Sub
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
StartAutoRefresh
End Sub
|
Note the highlighted line above. Change the value of PauseTime to change the refresh interval. PauseTime is the time to pause between refreshing, in seconds.
The user will be prompted to start auto-fresh each time a visio drawing is opened.
This is a minor problem with this method… If auto-refresh has been enabled you must first disable auto-refresh by launching the EndAutoRefresh macro through Tools > Macros > ThisDocument > EndAutoRefresh.
If you attempt to close the drawing and auto-refresh is still running, you may get an error message. To eliminate this problem, and not have the user prompted when the drawing is opened, remove the following lines from the macro.
|
Private Sub Document_DocumentOpened(ByVal doc As IVDocument)
StartAutoRefresh
End Sub
|
If you do remove the above lines from the macro, you will need to select through Tools > Macros > ThisDocument > StartAutoRefresh to start auto-refresh.