I have a workbook on a share drive that is used by multiple people. In the event that someone leaves the workbook open after using it, I have a timer function that pops up a splash screen after 4 minutes of inactivity which states, "This workbook will close in 1 minute if there is no further activity". If there is no further activity in that minute, the workbook closes.
The code works fine...unless the workbook is manually closed in that minute between the splash screen and when the timer would have closed the workbook. If that happens, the workbook closes normally and then briefly reopens and closes a minute later when the timer would have closed the workbook.
Is there any code to prevent this?
Public RunWhen As Double
Public Const cRunIntervalSeconds = 300 'FIVE minutes
Public Const cRunWhat = "CloseTheWorkbook"
Public SplashRunWhen As Double
Public Const cSplashRunIntervalSeconds = 240 'FOUR minutes
Public Const cSplashRunWhat = "SplashScreen_Open"
Sub Timer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True
SplashRunWhen = Now + TimeSerial(0, 0, cSplashRunIntervalSeconds)
Application.OnTime EarliestTime:=SplashRunWhen, Procedure:=cSplashRunWhat, Schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=False
Application.OnTime EarliestTime:=SplashRunWhen, Procedure:=cSplashRunWhat, Schedule:=False
End Sub
Sub CloseTheWorkbook()
With ActiveWorkbook
.RunAutoMacros xlAutoClose
.Save
.Close
End With
End Sub
Sub SplashScreen_Open()
SplashScreen.Show
End Sub
Bookmarks