Save and exit Excell after a certain amount of time.


Posted by David on December 21, 2001 12:32 PM

How could I make a worksheet save and exit after a certain time period, say, 5 minutes?

Thanks a bunch!
David

Posted by Ivan F Moala on December 21, 2001 12:56 PM

Here is one way to do it.
It is a routine I helped someone on this board with...


Dim Lasttime As Double
Dim Thistime As Double

Sub Auto_Open()
Application.OnEntry = "zerotime"
Lasttime = Now
Thistime = Now
CounterTime
End Sub

Sub Auto_Close()
Application.StatusBar = False
Application.OnEntry = ""
Application.OnTime Now() + TimeSerial(0, 0, 1), procedure:="countertime", schedule:=False

End Sub

Sub CounterTime()
Thistime = Now - Lasttime
Application.StatusBar = "Unused for " + Format(Thistime, "hh.mm.ss") + ". Closes in 00.05.00"
If Thistime > TimeSerial(0, 5, 0) Then
ThisWorkbook.Save
Auto_Close
ThisWorkbook.Close
End
End If
Application.OnTime Now() + TimeSerial(0, 0, 1), "countertime"
End Sub

Sub Zerotime()
Lasttime = Now()
End Sub

HTH

Ivan



Posted by David on December 21, 2001 2:18 PM

Re: Save and exit Excell after a certain amount of inactivity.

Thanks a lot Ivan! How about closing the spreadsheet after a certain time of inactivity?

Thanks again!!
David