here's a link to the earlier answer.
I think you have the code in the wrong places.
This should be in a standard module
'---------------------------------------------------------------------------------------
' DateTime : 09/05/2007 08:43
' Author : Roy Cox (royUK)
' Website : Clck here for more examples and Excel Consulting
' Purpose : Place in a standard module
' Disclaimer; This code is offered as is with no guarantees. You may use it in your
' projects but please leave this header intact.
'---------------------------------------------------------------------------------------
Option Explicit
Public EndTime
Sub RunTime()
Application.OnTime _
EarliestTime:=EndTime, _
Procedure:="CloseWB", _
Schedule:=True
End Sub
Sub CloseWB()
Application.DisplayAlerts = False
With ThisWorkbook
.Saved = True
.Close
End With
End Sub
Place this in the Workbook_Open event
Option Explicit
Private Sub Workbook_Open()
EndTime = Now + TimeValue("00:05:00")
RunTime
End Sub
Place this in each worksheet to detect any changes
Private Sub Worksheet_Change(ByVal Target As Range)
If EndTime Then
Application.OnTime _
EarliestTime:=EndTime, _
Procedure:="CloseWB", _
Schedule:=False
EndTime = Empty
End If
EndTime = Now + TimeValue("00:10:00")
RunTime
End Sub
Bookmarks