ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Auto saving & closing a file after inactivity (https://www.excelbanter.com/excel-programming/373185-auto-saving-closing-file-after-inactivity.html)

[email protected]

Auto saving & closing a file after inactivity
 
Hello:
I would appreciate help with this one:
What code do I need to place in "Workbook Open" so that after 10
minutes of no activity, the file is automatically saved and closed.

TIA
Vinay


skatonni[_4_]

Auto saving & closing a file after inactivity
 

See http://vbaexpress.com/kb/getarticle.php?kb_id=516 for a method tha
includes changing the right-click menu and using a password.

For your purposes this simplified version should suffice.


Code
-------------------
'<< START OF CODE FOR THISWORKBOOK MODULE
'http://vbaexpress.com/kb/getarticle.php?kb_id=516
Private Sub Workbook_Open()
Run "StartTimer"
End Sub

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Run "DisableTimer"
Run "StartTimer"
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
Run "DisableTimer"
Run "StartTimer"
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Run "DisableTimer"
Run "StartTimer"
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Run "DisableTimer"
End Sub
'<< END OF CODE FOR THISWORKBOOK MODULE

'<< START OF CODE FOR REGULAR MODULE
'http://vbaexpress.com/kb/getarticle.php?kb_id=516
Public IdleTime As Date

Sub StartTimer()
IdleTime = Now + TimeValue("00:10:00")
Application.OnTime IdleTime, "SaveAndClose"
End Sub

Sub DisableTimer()
On Error Resume Next
Application.OnTime EarliestTime:=IdleTime, _
Procedu="SaveAndClose", Schedule:=False
End Sub

Sub SaveAndClose()
With ThisWorkbook
.Save
.Close
End With
End Sub

'<< END OF CODE FOR REGULAR MODULE
-------------------

--
skatonn
-----------------------------------------------------------------------
skatonni's Profile: http://www.officehelp.in/member.php?userid=418
View this thread: http://www.officehelp.in/showthread.php?t=120318

Posted from - http://www.officehelp.i



All times are GMT +1. The time now is 05:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com