I have been around the interwebs all day and found multiple posts on multiple forums about this but I cannot get it to work correctly no matter what I've tried. Can someone please tell me why my timer never stops and restarts? I start the timer on workbook open and no matter how many different macros i run that begin with stoptimer and end with starttimer, the workbook always shuts down exactly 15 minutes after original open. What am I doing wrong?
Code:
Public RunWhen As Double
Public Sub StartTimer()
On Error Resume Next
RunWhen = Now + TimeValue("00:15:00") ' hh:mm:ss
Application.OnTime EarliestTime:=RunWhen, Procedure:="CloseDownFile", Schedule:=True
End Sub
Public Sub CloseDownFile()
StopTimer
Dim bCancel As Boolean
Application.run "ThisWorkbook.Workbook_BeforeClose", bCancel
On Error Resume Next
Application.StatusBar = "Inactive File Closed: " & ThisWorkbook.Name
ThisWorkbook.Close SaveChanges:=False
End Sub
Public Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedure:="CloseDownFile", Schedule:=False
End Sub