I have a VBA sub that need to run at the change of every hour. so at 7:00, 8:00, etc... As of right now I can get it to run every 60 min but in order for it to run on the hour the operator must start the timer exactly on the hour. my code that im using for this is as follows:
Public RunWhen As Double
Public Const cRunIntervalSeconds = 3600
Public Const cRunWhat = "transfer"
-----------------------------------------------------------------------
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
End Sub
I have been trying to find a way to get this to run exactly on the hour unsuccessfully for a while now, every place I look just tells me to do exactly what i have already done and just make sure i start it exactly on the hour.
for example: If the operator doesn't get to the station until 7:10 and hits the button that runs the code, I still want it to execute the sub called "transfer" at 8:00 then 9:00 and so on.
how would you suggest I modify or add to this code to get it to accomplish what I am trying to do? thank you for the help!
as requested, my favorite formula as answer:
because: it is short and should be 100% self-explaining :D