This answer is provided by Tushar Mehta
 

ID: 6

Category: Excel Automation

Question: How do I close a workbook that hasn't been used in 5 minutes?

Answer: In the Workbook module, put the following code:

Option Explicit
Private Sub Workbook_Open()
    start_Countdown
    End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    stop_Countdown
    start_Countdown
    End Sub
In a standard module, enter the following code:
Option Explicit
Public Close_Time As Date
Sub start_Countdown()
    Close_Time = Now() + TimeValue("00:05:00")
    Application.OnTime Close_Time, "close_WB"
    End Sub
Sub stop_Countdown()
    Application.OnTime Close_Time, "close_WB", , False
    End Sub
Sub close_wb()
    ThisWorkbook.Close True
    End Sub

ExtendedLink:  


Website material copyright 2003-2006 TM Faculty Associates