Hello,
I've got one workbook with 2 macros (I did not originally create them): macro1 resets some cell values (for graphical purposes only) and then sets a string to equal a time (i.e. 8:30AM) in a cell and then uses OnTime with that string to schedule macro 2 for that time. Macro2 then makes a pdf from the sheet and emails it out. This report worked fine, originally.
The other workbook has different data, but the setup with regards to the macros is similar. I has the same 2 macros from the first workbook. I copied them over and renamed the macros, named ranges and references to such to make sure they didn't intersect (even though I don't think they should have). This second report only runs once a week, on the day specified by a dropdown on the sheet. In this case, macro1's OnTime schedules macro3 which checks the day of the week. If it is wrong day, it runs macro1 so it will check again tomorrow. If it is the correct day, it runs macro 2.
Since these reports are supposed to run automatically, I've added lines to the end of both macro2s so that they run their macro1s to run/check the next day. Everything comes out fine with regards to the reports and emailing, with the exception of the timing.
Sometimes the reports don't run at all and sometimes they run at the wrong time. Ideally the daily report runs every day at 8:30AM and the weekly report runs wednesday at 10PM. Unfortunately, I've had the weekly report get run at 8:30AM and the daily report run at 12:30PM.
I'm very confused as to why these sort of things keep happening. I really can't understand how they haven't implemented some sort of way to look at scheduled events. Is there some sort of better alternative to OnTime?
I don't know if it's relevant, but there's a DoEvents after the OnTime in macro1
What purpose would the DoEvents serve? Could it be a problem?
I can post the rest of the code if anyone wants, but it's kinda long so I figured I'd wait until then.
I've got one workbook with 2 macros (I did not originally create them): macro1 resets some cell values (for graphical purposes only) and then sets a string to equal a time (i.e. 8:30AM) in a cell and then uses OnTime with that string to schedule macro 2 for that time. Macro2 then makes a pdf from the sheet and emails it out. This report worked fine, originally.
The other workbook has different data, but the setup with regards to the macros is similar. I has the same 2 macros from the first workbook. I copied them over and renamed the macros, named ranges and references to such to make sure they didn't intersect (even though I don't think they should have). This second report only runs once a week, on the day specified by a dropdown on the sheet. In this case, macro1's OnTime schedules macro3 which checks the day of the week. If it is wrong day, it runs macro1 so it will check again tomorrow. If it is the correct day, it runs macro 2.
Since these reports are supposed to run automatically, I've added lines to the end of both macro2s so that they run their macro1s to run/check the next day. Everything comes out fine with regards to the reports and emailing, with the exception of the timing.
Sometimes the reports don't run at all and sometimes they run at the wrong time. Ideally the daily report runs every day at 8:30AM and the weekly report runs wednesday at 10PM. Unfortunately, I've had the weekly report get run at 8:30AM and the daily report run at 12:30PM.
I'm very confused as to why these sort of things keep happening. I really can't understand how they haven't implemented some sort of way to look at scheduled events. Is there some sort of better alternative to OnTime?
I don't know if it's relevant, but there's a DoEvents after the OnTime in macro1
Code:
'Start the clock
Dim RptTime As String
RptTime = Format(Range("RunTimeW"), "hh:mm:ss")
Range("StatusW") = "Waiting since " & Now
'Wait until start time, then go to week day test
Application.OnTime TimeValue(RptTime), "WeekDayTest"
If Not Application.CalculationState = xlDone Then
DoEvents
End If
End Sub
I can post the rest of the code if anyone wants, but it's kinda long so I figured I'd wait until then.
Last edited: