Sean15
Well-known Member
- Joined
- Jun 25, 2005
- Messages
- 719
- Office Version
- 2010
- Platform
- Windows
Hi:
This code closes Excel workbook after two minutes of inactivity. But I noticed something odd. If I have two workbooks open, Excel closes the last open workbook when the code executes. Could code be adjusted so Excel will only close workbook SW 070222.xlsm after two minutes of inactivity? Code saved in VBA project module 1
File path: C:\Users\mycar34\Documents\Articles\SW 070222.xlsm
This code closes Excel workbook after two minutes of inactivity. But I noticed something odd. If I have two workbooks open, Excel closes the last open workbook when the code executes. Could code be adjusted so Excel will only close workbook SW 070222.xlsm after two minutes of inactivity? Code saved in VBA project module 1
File path: C:\Users\mycar34\Documents\Articles\SW 070222.xlsm
VBA Code:
Dim CloseTime As Date
Sub TimeSetting()
Application.CutCopyMode = False
CloseTime = Now + TimeValue("00:02:00")
On Error Resume Next
Application.OnTime EarliestTime:=CloseTime, _
Procedure:="SavedAndClose", Schedule:=True
End Sub
Sub TimeStop()
On Error Resume Next
Application.OnTime EarliestTime:=CloseTime, _
Procedure:="SavedAndClose", Schedule:=False
End Sub
Sub SavedAndClose()
ActiveWorkbook.Close Savechanges:=True
End Sub