简体   繁体   中英

Excel VBA Macros Scheduling

I would like to automatically start my macro @ 9:30Am and then to schedule it to run at every 15min and end running at 3:15pm. For example - Micro should first run @ 9:30am then at 9:45, 10:00, 10:15 & so on till 3:15pm. Can anyone help me with it?

Application.OnTime "09:15:00" + TimeValue("00:15:00"), "test", "15:15:00"  

In Excel you could use the Application.OnTime method which schedules a procedure to be run at a specified time in the future (either at a specific time of day or after a specific amount of time has passed). For example, to run it for the first time at 9 AM you could use the following code:

Application.OnTime TimeValue("9:30:00"), "my_Procedure"

In your procedure you could schedule next iteration will schedule next run in 15 mins:

Sub my_Procedure()

  ' your code here which runs every 15 mins

  Application.OnTime Now + TimeValue("00:00:15"), "my_Procedure"
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM