Private scheduledToRun As Boolean
Private runTime As Variant
Public Sub SheetChange()
Call CancelMacro
runTime = Now + TimeSerial(0, 15, 0)
Application.OnTime EarliestTime:=runTime, Procedure:="CloseReminder"
scheduledToRun = True
End Sub
Public Sub CloseReminder()
scheduledToRun = False
If MsgBox("You've been inactive for 15 minutes. Do you need to close the spreadsheet?", vbQuestion + vbYesNo) = vbYes Then
ActiveWorkbook.Close
Else
Call SheetChange
End If
End Sub
Public Sub CancelMacro()
If scheduledToRun Then Application.OnTime EarliestTime:=runTime, Procedure:="CloseReminder", Schedule:=False
End Sub