Autosave every 5 minutes

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
Can someone give me an example of how I can autosave a workbook every 5 minutes but include a message box advising of such? The message box should appear in front of anything that is going on, including userforms.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Can someone give me an example of how I can autosave a workbook every 5 minutes but include a message box advising of such? The message box should appear in front of anything that is going on, including userforms.
This can be tied to Workbook_Open and Workbook_BeforeClose events to call SaveIt when the workbook opens and call StopSaveIt when you close the workbook.
Code:
Public RunWhen
Sub SaveIt()
RunWhen = Now + TimeSerial(0, 5, 0)
Application.OnTime RunWhen, "saveit", , True
ThisWorkbook.Save
MsgBox "Your file " & ThisWorkbook.Name & " was just autosaved"
End Sub
Sub StopSaveIt()
On Error Resume Next
Application.OnTime RunWhen, "saveit", , False
End Sub
 
Upvote 0
Thank you - can I just clarify, does your code go in both the open and close events or one in each other and if so which?
 
Upvote 0
Thank you - can I just clarify, does your code go in both the open and close events or one in each other and if so which?

The code I posted goes in a standard module in the workbook you want to auto save. Then in a Thisworkbook module you would have:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call StopSaveIt
End Sub

Private Sub Workbook_Open()
Call SaveIt
End Sub
 
Upvote 0
Haha - I told them that every 10 minutes would be bad enough, but now they want it at 3 minutes, I'll let you know when they ask for it to be extended, I guess within the next 10 minutes!
 
Upvote 0
Slight problem now - I'm getting a run time error on closing, error number 1004 - 'Method 'OnTime' of object '_Application' failed....any ideas?
 
Upvote 0

Did you modify the code I posted in any way? Do you have any other workbook_beforeClose events in Thisworkbook or any other code in place that might interfere?

I am unable to reproduce the problem.
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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