我需要每10分钟执行一次宏。
这允许它在10分钟内工作
sub my_Procedure ()
msgbox "hello world"
end sub
sub test()
Application.OnTime Now + TimeValue("00:00:10"), "my_Procedure"
end sub
但这只能运作一次。如何让我的宏每10分钟执行一次?
答案 0 :(得分:30)
你应该使用这种模式:
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
答案 1 :(得分:6)
考虑:
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
所有标准模块..............确保在退出Excel之前运行StopTimer
注意强>
"分钟" TimeSerial中的参数是第二个参数。