close and saved after

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Close and Saved after 5 mins of inactivity code not saving

Close and Saved after 5 mins of inactivity code not saving

resolvedResolved · Low Priority · Version 2010

Emma has attended:
Excel VBA Introduction course

Close and Saved after 5 mins of inactivity code not saving

Hi,

The below code is supposed to save and close an excel spread sheet after 5 mins of inactivity,however it just closes and doesnt save. Can anyone tell me how to fix this?

Many thanks

This Workbook:

Private Sub Workbook_Open()
Call SetTimer
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopTimer
End Sub
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Call StopTimer
Call SetTimer
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
Call StopTimer
Call SetTimer
End Sub


Moduel 1:

Dim DownTime As Date
Sub SetTimer()
DownTime = Now + TimeValue("00:05:00")
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown()", Schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown()", Schedule:=False
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
With ThisWorkbook
.Saved = True
.Close
End With
End Sub

RE: Close and Saved after 5 mins of inactivity code not saving

Hi Emma,

Thank you for the forum question.



Almost everything in your code was correct. I have changed a little bit in the module (see code below). When you call a macro (Shutdown) it is without the brackets I also changed the Shutdown() macro a little bit.

It is working for me and I hope it will work for you. If not please let me know.


Dim DownTime As Date
Sub SetTimer()
DownTime = Now + TimeValue("00:05:00")
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown", Schedule:=True
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=DownTime, _
Procedure:="ShutDown", Schedule:=False
End Sub
Sub ShutDown()
Application.DisplayAlerts = False
ThisWorkbook.Close savechanges:=True

End Sub

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Trace Dependents / Precedents without the blue arrows

Rather than using the toolbar you can press CTRL+] which is the equivelent of trace dependants and CTRL+[ for precendants. Both of these ways though will not show the blue arrows but jump to the cell containing the formula.

View all Excel hints and tips


Server loaded in 0.07 secs.