Application.Ontime loop does not execute if the required time is before Now()

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
558
Office Version
  1. 365
Platform
  1. Windows
This is more of an observation, than a question, but I would like to hear others opinions.

With this loop:

VBA Code:
        With Sheet10
        'Use Unique times to avoid duplicates
            TimeToRun = CDate(.Range("AP" & 2 + i).Value)
            RaceIDTimeToRun = .Range("AF" & 2 + i).Value
            Application.OnTime EarliestTime:=TimeValue(TimeToRun), Procedure:="myMacro1", Schedule:=False
            Application.OnTime EarliestTime:=TimeValue(RaceIDTimeToRun), Procedure:="myMacro2", Schedule:=False
        End With

What this does is read in the values to execute the Application.OnTime routine at various scheduled times.

However, what I have found is that if the execution time being read in is before the current time, then no times are set up at all to execute. Generally, I have to put in some manual code that reads in the read value after the current time to make it work.

I haven't found any information about this.

I look forward to hearing your thoughts or being corrected I am approaching this incorrectly.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You know that code is cancelling OnTIme, not setting it?
 
Upvote 0
Solution
Hi Rory, thanks for that. I ended up figuring that out a short while ago. The usage of Application.OnTime is new to me. I only started with it over the weekend to automate my model. Cheers
 
Upvote 0

Forum statistics

Threads
1,223,863
Messages
6,175,052
Members
452,607
Latest member
OoM_JaN

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top