auto run a macro

G

garima agrawal

Hi,

I want to run a macro inMS excel, in specific time
intervals automatically. I need to update my data and
calculations in every five minutes for that I am using
formulas and macros.

Will it be possible to run a macro automaically, like auto
refresh facility in MS excel.

Thanks

Garima
 
J

John Green

Garima,

Use the OnTime method to schedule a macro. The following code (from Bill Manville, originally) shows how to repeat the same code
every ten seconds:

Dim NextTime As Date

Sub DoItRepeatedly()
DoItAgain
End Sub

Sub DoItAgain()
DoIt ' this is your procedure
NextTime = Now + TimeValue("00:00:10") ' 10 seconds on
Application.OnTime NextTime, "DoItAgain"
End Sub

Sub StopDoingIt()
Application.OnTime NextTime, "DoItAgain", schedule:=False
End Sub

Sub Auto_Close() ' otherwise it will re-open and do it again!
StopDoingIt
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top