Ontime Event Going haywire at midnight

Drumin_Phreak

New Member
Joined
Oct 10, 2016
Messages
25
Hello! I have a excel project that starts an ontime event on workbook open. This thing works fantastic! However, when midnight rolls around it crashes. After doing some research I have surmised that the problem is when the date changes, the time is now After the initial time set. I tried to include the now function (dTime2= Now + TimeValue ("00:05:00") and this does nothing. The one that currently works is:

Code:
dTime2 = Time + TimeValue("00:05:00")
  Application.OnTime dTime2, "AutoSaves"

I have been struggling with this for quite sometime. If I could get any help it would greatly be appreciated.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
When do you want 'AutoSaves' to run?
 
Upvote 0
Use Now rather than Time, since that will include a Day part.
 
Upvote 0
Open Resumption of Midnight shift, I did indeed try the "NOW" function so my code is

Code:
[COLOR=#333333]dTime2 = Now + TimeValue("00:05:00")
[/COLOR][COLOR=#333333]  Application.OnTime dTime2, "AutoSaves"[/COLOR]

However, when the hour struck Midnight it froze up and went into an infinite loop trying to save.

My next idea is:

Can I some how put a timer when the workbook is opened to suspend auto saving at like 23:45 and Resume saving at 00:05 the next day?
 
Upvote 0
So it seems like no matter what I do it still goes crazy right at midnight, they do a reload and it works perfect from there on out.
 
Upvote 0
I can't see why it would do what you're describing but as a workaround, you could do something like this:

Code:
dTime2 = Now + TimeValue("00:05:00")
if Hour(dTime2) = 23 and Minute(dTime2) >=50 then dTime2 = Date() + 1 + TimeValue("00:05:00")
 
Upvote 0
I can't see why it would do what you're describing but as a workaround, you could do something like this:

Code:
dTime2 = Now + TimeValue("00:05:00")
if Hour(dTime2) = 23 and Minute(dTime2) >=50 then dTime2 = Date() + 1 + TimeValue("00:05:00")


RoryA,

I sincerely appreciate your suggestions, but nothing I do seems to help this situation. I am so confused about what i can do to fix this issue.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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