views:

305

answers:

1

I have a need to run a piece of code every 120 seconds. I am looking for an easy way to do this in VBA. I know that it would be possible to get the timer value from the Auto_Open event to prevent having to use a magic number, but I can't quite get how to fire off a timer to get something to run every 120 seconds.

I don't really want to use an infinite loop with a sleep if I can avoid it.


EDIT:

Cross-post based on an answer provided is at: http://stackoverflow.com/questions/2341762/excel-vba-application-ontime-i-think-its-a-bad-idea-to-use-this-thoughts-eit

A: 

(This is paraphrased from the MS Access help files. I'm sure XL has something similar.) Basically, TimerInterval is a form-level property. Once set, use the sub Form_Timer to carry out your intended action.

Sub Form_Load()
    Me.TimerInterval = 1000 '1000 = 1 second
End Sub

Sub Form_Timer()
    'Do Stuff
End Sub
PowerUser
Thanks for the advice, however I don't want to do this as part of a form.
FinancialRadDeveloper