Home » excel » excel – Using VBA Application.ontime for a time tomorrow

excel – Using VBA Application.ontime for a time tomorrow

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have written a timer in VBA in excel using application.ontime that makes a sound and gives a message box when an end time is reached.

This works fine when the time is later in the same day, but when it goes to the next day the timer ends right away, as that time has already passed today.

E.g., if the time is currently 7:00 pm and I want the timer to go off at 6:00 am tomorrow, then the timer goes off immediately because 6:00 am has already passed today.

Is there any way of incorporating the date into the application.ontime call? Am I better off using some other function?

How to&Answers:

You can use:

Application.OnTime Date + 1 + Timeserial(6,0,0), "macro_name"

as long as you don’t close Excel before 6am tomorrow. 😉