Simple Visio Macro to Refresh Linked Data with < 1 Minute Intervals

by Aaron D-H 30. January 2009 06:23

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.

Tags:

Comments


July 21. 2009 23:03
Daniel Steiger
I like how you write.Are you interesting in a part time writer job?


August 13. 2009 23:59
Baume Mercier Mens Hampton
I am quite interesting in this topic hope you will elaborate more on it in future posts.


August 15. 2009 21:56
Nike Wt0024413
I like your blog curently we are looking for a part time article writer would you be interested?


August 17. 2009 20:05
Jill Stuart Womens Retrograde
Please let me know if you are interested to work as article writer for me? I can offer $10/article.


August 26. 2009 09:23
bad credit loans
I think your blog need a new wordpress template. Downalod it from http://templates.wordpressguru.in, The site has nice and unique wordpress templates.


August 26. 2009 09:36
Baume Mercier Classima
Hmm strange this post is totaly irrelevant to the search query I entered in google but it was listed on the first page.

Comments are closed

About the Author

I'd like to introduce myself to you... My name is Aaron Daisley-Harrison.  I have worked in the software engineering field for a number of years, and as an  Application Architect have created solutions for many industry verticals; worked with both Sun Microsystem and Microsoft technologies; Developed SQL database engines as well as full text search systems; and Knowledge management systems.   I am currently doing contract work out of the Pacific North West and have lately been focusing on Microsoft technologies like SharePoint 2007/2010, WCF, Identity Framework, JQuery, Xml and Silverlight.
[more]



 Digg!

 

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009 Aaron G. Daisley-Harrison - All Rights Reserved.