save and close file after 30 minutes

mabaud

New Member
Joined
Apr 16, 2002
Messages
21
I would like a timer to start as soon as I open a file.
After 30 minutes, I would like the file to be saved and closed.
How can I do that?
thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I saved this thread as a text file but I can't seem to find the actual thread on the board. Anyway modify to suit

Timing out a Workbook
Is there a way to set up a workbook so that if a user leaves it open and walks away from his/her machine, Excel will save the changes and close the workbook?

In my world, various people, across many states, open and edit some of the same workbooks via a network setup. We have not shared the workbooks because of some of the limitations that sharing causes. On a good day the user opens the workbook, makes the changes that are necessary, saves his/her changes, and closes the workbook thus allowing the next user to open it. However, we know every day is not a good day - on these "not so good days" days the user opens the workbook, makes some changes, gets distracted by a donut drop off, and walks off to investigate leaving the workbook open. Now the person is ATL whois trying to open it to make changes can only open as a READ-ONLY...

Does anyone have any suggestions?
_________________
Beth

13 Mar 2003 16:52


Richie(UK)
MrExcel MVP


Joined: 18 May 2002
Posts: 1428
Location: Worcester, England

Hi Beth,

See if this does what you need - it closes after 20 seconds of inactivity (defined in this case as no calculation or change of selection).

In a general module:

code:
--------------------------------------------------------------------------------
Dim DownTime As Date

Sub SetTime()
DownTime = Now + TimeValue("00:00:20")
Application.OnTime DownTime, "ShutDown"
End Sub

Sub ShutDown()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub

Sub Disable()
On Error Resume Next
Application.OnTime EarliestTime:=DownTime, Procedure:="ShutDown", Schedule:=False
End Sub
--------------------------------------------------------------------------------



In the ThisWorkbook object:
code:
--------------------------------------------------------------------------------
Private Sub Workbook_Open()
MsgBox "This workbook will auto-close after 20 seconds of inactivity"
Call SetTime
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Disable
End Sub

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Call Disable
Call SetTime
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
Call Disable
Call SetTime
End Sub

HTH
 
Upvote 0
Hello, Have you found that the code above closes in the time specified even if there has been activity? I changed mine to 5 minutes and after 5 minutes it just saved and closed when I was in the middle of something?

Kind Regards

Nathan
 
Upvote 0

Forum statistics

Threads
1,215,749
Messages
6,126,661
Members
449,326
Latest member
asp123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top