Hi Community

I found this post sometime ago, I am trying to acomplish the same but it seems not to run properly. The Disable Sub is not working. It doesn't matter if i select or click always closes the app at the time calculated in the start. Any help to arrange this.

Thank you

Jose Luis


POST FOUND:

"What I would like to do is if there has been no activity on the workbook
for 10 minutes it will save and close automatically. Any pointers most appreciated.
Taffy"


Taffy, here is a macro that will do it, I don't remember who wrote it, maybe
somebody will see it and let me know who to give credit to.
As is it will save and then close the workbook after 20 seconds of
inactivity, use to test then change the 20 seconds to your time

Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!


**** these in "ThisWorkbook"
Private Sub Workbook_Open()
MsgBox "This workbook will auto-close after 30 seconds of inactivity"
Call SetTime
End Sub

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

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Call Disable
Call SetTime
End Sub

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


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Call Disable
Call SetTime
End Sub

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


*** these in a module
Sub SetTime()
Dim DownTime As Date
DownTime = Now + TimeValue("00:00:50") 'change time as needed
Application.OnTime DownTime, "ShutDown"
End Sub

Sub ShutDown()
'MsgBox "El sistema se cerrara por inactividad", vbExclamation
ThisWorkbook.Save
ThisWorkbook.Close
End Sub


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