Scheduling a Macro to Run x Minutes in the Future

You can schedule a macro to run at a time at a certain point in the future. The following macro runs something 2 minutes and 30 seconds from now:

Sub ScheduleAnything()

' This macro can be used to schedule anything WaitHours = 0 WaitMin = 2 WaitSec = 30

NameOfScheduledProc = "CaptureData" ' — End of Input Section

' Determine the next time this should run

NextTime = Time + TimeSerial(WaitHours, WaitMin, WaitSec)

' Schedule ThisProcedure to run then

Application.OnTime EarliestTime:=NextTime, Procedure:=NameOfScheduledProc End Sub

0 0

Post a comment