How to have vba execute every 10 minutes?
Consider:
Public RunWhen As Double
Public Const cRunWhat = "my_Procedure"
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 10, 0)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedure:=cRunWhat, schedule:=False
End Sub
Sub my_Procedure()
MsgBox "hello world"
Call StartTimer
End Sub
all in a standard module..............be sure to run StopTimer before exiting Excel
NOTE
The "minute" argument in TimeSerial is the second argument.
You should use this pattern:
Sub my_Procedure()
MsgBox "hello world"
Call test ' for starting timer again
End Sub
Sub test()
Application.OnTime Now + TimeValue("00:10:00"), "my_Procedure"
End Sub