How to do vba every 10 minutes?

I need my macro to run every 10 minutes.

This allows him to work in 10 minutes.

sub my_Procedure () msgbox "hello world" end sub sub test() Application.OnTime Now + TimeValue("00:00:10"), "my_Procedure" end sub 

But this only works once. How can I execute my macro every 10 minutes?

+8
vba excel-vba excel
source share
2 answers

You should use this template:

 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 
+22
source share

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 

everything in the standard module ...... be sure to run StopTimer before exiting Excel

Note

The minute argument in TimeSerial is the second argument.

+6
source share

All Articles