Hello,
First, happy new year. I work in Excel with a VBA script. The purpose of my script is that every 5 seconds a procedure will be executed. This works well.
If my workbook is not active, it does not work. Or when I work with another workbook. Or when I work with another program. Then the script will stop to execute. It looks like a break.
I have tried several scripts that have the same effect. I want the script continues normally with execution.
Can someone give me a solution?
Thanks so much!
grid
First, happy new year. I work in Excel with a VBA script. The purpose of my script is that every 5 seconds a procedure will be executed. This works well.
If my workbook is not active, it does not work. Or when I work with another workbook. Or when I work with another program. Then the script will stop to execute. It looks like a break.
I have tried several scripts that have the same effect. I want the script continues normally with execution.
Code:
Public RunWhen As Double
Public Const cRunIntervalSeconds = 5 ' 5 seconds
Public Const cRunWhat = "TheSub" ' the name of the procedure to run
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
End Sub
Sub TheSub()
MsgBox "Example: every 5 seconds I see this message. Here comes the 2nd procedure."
StartTimer ' Reschedule the procedure
End Sub
Can someone give me a solution?
Thanks so much!
grid
Last edited: