Hi everyone,
I know this is an issue raised by many people in many locations online, but I still can't work out what is going wrong with my Application.OnTime subs...
I have an ontime function to set a timer to detect when a workbook is active. After 10 mins, a warning userform pops up to advise that the workbook has been inactive and if the UF is not cancelled manually within 60secs the workbook saves and closes.
Frequently, the workbook after closing manually will reopen and attempt to run the sub that opens the warning userform. This I gather is due to the time not having reset itself properly.
I have the selection change in the workbook trigger the stop and then the reset timer subs. Both of these subs are written out exactly the same to avoid errors. I have an error reporting debug.print line inserted in the stop function that seesm to indicate that every now and then the 'stop' function doesn't trigger. It is this missed stop function that must then mean that the .ontime function is still running and then triggers the reopening after the workbook closes.
This just seems to happen every so often. Obviously I have the on error line which is what enables the routine to keep running when this errors out, but I was just wondering what things can cause the ontime method to error and thus fail to reset? Any ideas? Code below:
Public DownTime, dtime As Double
Sub SetTimer()
DownTime = Now + TimeSerial(0, 10, 0)
Application.OnTime DownTime, "Showwarning", , True
Debug.Print "reset to " & DownTime
End Sub
Sub StopTimer()
On Error GoTo skip
Application.OnTime DownTime, "Showwarning", , False
Debug.Print "succesfully stopped " & DownTime
GoTo autoclose
skip:
Debug.Print "reset failed " & DownTime
autoclose:
End Sub
Bookmarks