Timer to detect idle time?

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
R

Robert Crandal

If no changes are made to my workbook after
5 minutes, I want to autosave and close the
workbook. Is something like this possible?

thank you
 
Hi,

Yes that's possible with code.

These get pasted into 'ThisWorkbook'

Private Sub Workbook_Open()
Call SetDelay
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Disable
End Sub

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Call Disable
Call SetDelay
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
Call Disable
Call SetDelay
End Sub

Right click 'ThisWorkbook' insert module and paste this in

Dim DownTime As Date

Sub SetDelay()
DownTime = Now + TimeValue("00:05:00") 'change time as needed
Application.OnTime DownTime, "CloseBook"
End Sub

Sub CloseBook()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub

Sub Disable()
On Error Resume Next
Application.OnTime EarliestTime:=DownTime, _
Procedure:="CloseBook", Schedule:=False
End Sub

Save and close the workbook and on reopening 5 minutes of inactivilty will
cause it to save and close.
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
Back
Top