detecting application idle time in Excel 2000

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can you program excel to detect idle time and use this to exit the
program after a set period of time.
 
Hi!

Try this idea.

Copy next 4 codes ThisWorkbook module.

'***********************************************************
Private Sub Workbook_Open()
On Error Resume Next
Application.OnTime RunSubProgram, "SaveAndClose", , False
On Error GoTo 0
RunSubProgram = Now + TimeSerial(0, Minutes, 0)
MsgBox ("Application exit, if you don't use it " & vbCrLf & _
Minutes & " minutes!"), , "Warning!"
Application.OnTime RunSubProgram, "SaveAndClose", , True
End Sub
'***********************************************************
Private Sub Workbook_SheetChange(ByVal Taulukko As Object, ByVal Kohde As
Range)
On Error Resume Next
Application.OnTime RunSubProgram, "SaveAndClose", , False
On Error GoTo 0
RunSubProgram = Now + TimeSerial(0, Minutes, 0)
Application.OnTime RunSubProgram, "SaveAndClose", , True
End Sub
'***********************************************************
Private Sub Workbook_SheetSelectionChange(ByVal Taulukko As Object, ByVal
Kohde As Range)
On Error Resume Next
Application.OnTime RunSubProgram, "SaveAndClose", , False
On Error GoTo 0
RunSubProgram = Now + TimeSerial(0, Minutes, 0)
Application.OnTime RunSubProgram, "SaveAndClose", , True
End Sub
'***********************************************************
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime RunSubProgram, "SaveAndClose", , False
On Error GoTo 0
End Sub
'***********************************************************
And copy next codes Module1
'***********************************************************
Public RunSubProgram As Double
Public Const Minutes = 15

Public Sub SaveAndClose()
ThisWorkbook.Close SaveChanges:=True
End Sub
'***********************************************************
Regards,
Kari J Keinonen
 
Back
Top