Interesting question. This seems to work and could be useful to me too in something I developed.
For the test, I used a worksheet SelectionChange event (the cell pointer is moved) to set an OnTime event to run. OnTime event must be in a normal module, not a worksheet or workbook module. You might want a different event depending on your spreadsheet. Maybe a SheetChange event for when a cell in any open workbook is altered?
Anyway, two bits of code, this one in a standard module
Code:
Option Explicit
Public mtLastChange As Date
Public mtTimeLimit As Date
Sub CloseFileIfInactive()
If Now > mtLastChange + mtTimeLimit - TimeValue("00:00:01") Then ThisWorkbook.Close
End Sub
And in my test, this code in a worksheet module,
Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
mtTimeLimit = TimeValue("00:05:00")
mtLastChange = Now
Application.OnTime mtLastChange + mtTimeLimit, "CloseFileIfInactive"
End Sub
Modify to suit. Especially the Workbook.Close you might do differently - save file & then close, whatever. When testing, I set the mtTimeLimit to "00:00:10" but put it to 5 minutes above to suit real application.
HTH,
Fazza