Auto run a macro

C

Clarke

I need this to run automatically every specified amount of time, but this
code isn't working...

Public Sub AutoDelay()

Application.OnTime When:=Now + TimeValue("00:05:00"),
Name:="AutoSave"

End Sub
Public Sub AutoSave()
ActiveDocument.Save
End Sub

If you have a better suggestion, please post it. Thanks!
 
P

Peter

Some things to keep in mind when using the OnTime method:
- The macro that is going to be called at each interval needs to be public.
- You need to specify the name of the module with the macro name.
- Inside that macro, you need to reset the timer.

Public Sub AutoDelay()
Application.OnTime When:=Now + TimeValue("00:05:00"), Name:="Module1.AutoSave"
End Sub
Public Sub AutoSave()
ActiveDocument.Save
Application.OnTime When:=Now + TimeValue("00:05:00"), Name:="Module1.AutoSave"
End Sub

hth,

-Peter
 

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