laxster
01-05-2010, 10:13 AM
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!
ajetrumpet
01-05-2010, 10:50 AM
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.
HaHoBe
01-05-2010, 11:01 AM
Hi, laxster,
use Worksheet-Events and OnTime for this.
Code for ThisWorkbook:
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
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
laxster
02-01-2010, 12:55 PM
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:
Sub EndProc()
ThisWorkbook.Close True
ActiveSheet.ShowAllData
Err.Clear
Range("A2").Select
End Sub
How would I get this to change?
ghudson
02-02-2010, 11:21 AM
Change the order of events...
ActiveSheet.ShowAllData
Range("A2").Select
ThisWorkbook.Close True