title: Excel closing after time of user inactivity
body: <p>I am fairly new at VBA and have code in place that will close excel after inactivity. I am not sure what excel defines as inactivity and I couldn't pick up a pattern. If someone could explain this to me I would really appreciate it.</p>
  
  <p>CODE IN THE "THIS WORKBOOK" SECTION</p>
  
  <pre><code>Option Explicit
  
  Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
  ResetTimer
  End Sub
  
  Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
  ResetTimer
  End Sub
  
  Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
  ResetTimer
  End Sub
  </code></pre>
  
  <p>CODE IN A STANDARD MACRO</p>
  
  <pre><code>Public CloseDownTime As Variant
  
  Public Sub ResetTimer()
  On Error Resume Next
  If Not IsEmpty(CloseDownTime) Then Application.OnTime EarliestTime:=CloseDownTime, Procedure:="CloseDownFile", Schedule:=False
  CloseDownTime = Now + TimeValue("00:10:00") ' hh:mm:ss
  Application.OnTime CloseDownTime, "CloseDownFile"
  End Sub
  
  Public Sub CloseDownFile()
  On Error Resume Next
  Application.StatusBar = "Inactive File Closed: " &amp; ThisWorkbook.Name
  ThisWorkbook.Close SaveChanges:=True
  End Sub
  </code></pre>