Force quit Excel

laxster

Registered User.
Local time
Yesterday, 22:00
Joined
Aug 25, 2009
Messages
145
Is it possible for Excel to force quit after a certain period of inactivity?

I have a spreadsheet that unfortunately can't be shared due to a couple issues that arise whilst sharing. I'm just concerned that if someone opens the sheet and walks away, they lock out other people who need to use it.

If there was a way of forcing Excel to automatically save and close the spreadsheet after 5 minutes of inactivity, that would be perfect!
 
i suppose one thing you could do would be to set a timer, and then after 5 minutes, quit and save the application. i'm not sure if Excel has a dirty event, but you might check. You'l have to use that to detect weather or not they are typing or what not. You have to detect somehow if they are still at the desk.
 
Hi, laxster,

use Worksheet-Events and OnTime for this.

Code for ThisWorkbook:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    SetBack
End Sub

Private Sub Workbook_Open()
    StartProc
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    StartProc
End Sub
A standard module
Code:
Dim datEnd As Date
Public Const datIntervall As Date = "00:05:00"  

Sub StartProc()
  On Error Resume Next
  Application.OnTime EarliestTime:=datEnd, Procedure:="EndProc", Schedule:=False
  datEnd = Now + datIntervall
  Application.OnTime datEnd, "EndProc"
End Sub

Sub EndProc()
  ThisWorkbook.Close True
End Sub

Sub SetBack()
  Application.OnTime EarliestTime:=datEnd, Procedure:="EndProc", Schedule:=False
End Sub
Save the workbook and wait for 301 seconds...

Ciao,
Holger
 
So a month later I have another question. I'd like to add a piece that causes the worksheet to place the active cell at A2 and remove applied filters when the timer hits. I tried inserting this piece of code, but it doesn't do the trick:

Code:
Sub EndProc()
  ThisWorkbook.Close True
  ActiveSheet.ShowAllData
Err.Clear
Range("A2").Select
End Sub

How would I get this to change?
 
Change the order of events...

ActiveSheet.ShowAllData
Range("A2").Select
ThisWorkbook.Close True
 

Users who are viewing this thread

Back
Top Bottom