Auto Run Subroutine every 1 Second in Excel VBA

The following snippet of code will auto run subroutine every 1 second in Excel VBA


Sub Cal_Range()
Range(“A1:B100″).Calculate
Application.OnTime DateAdd(“s”, 1, Now), “Cal_Range”
End Sub

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

 

You must be logged in to post a comment.