Autosave Every 5 minutes.......

Guitarfool5931

Board Regular
Joined
Oct 6, 2008
Messages
83
I'm trying to write a macro in excel that will save the document every couple of minutes. After searching the forums here for a bit I found something that might work:

Sub test()
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 30
waittime = TimeSerial(newHour, newMinute, newSecond)


Do
ActiveWorkbook.Save
Loop

End Sub

The only thing about this is that it runs constantly and won't stop saving. Is there a way to do this where it will only save every 5 minutes or so???
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Thanks! Found something I might be able to use there. But not sure how to write the code in the macro??:


<CODE>Sub test()</CODE></PRE><CODE>

Do
Application.OnTime Now + TimeValue("00:05:00"), "ActiveWorkbook.Save"
</PRE>
Loop</PRE>
End Sub</PRE>
Sorry, I'm a newbie at macros.


</PRE></CODE>
 
Upvote 0
Put this code in the ThisWorkbook module

Code:
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub

And, put this code in a standard module (e.g. Module1)
Code:
Sub SaveThis()
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True

Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub
 
Upvote 0
Do I have to run this code everytime I open up the workbook? Not sure if I put this in right but it seems to work when I run it.
 
Upvote 0
By putting the Workbook_Open event in the ThisWorkbook module, it will automatically trigger the first save 5 minutes after the workbook is opened (and all subsequent saves).
 
Upvote 0
So this was running fine til today it started saving about every 2 minutes instead of five. I haven't changed anything but here is what the code looks like. Might have entered it wrong.


Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub

____________________________________________________________
Sub SaveThis()
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True

Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub
 
Upvote 0
That looks OK... Is it possible that some of the saves are autorecover saves? Check the autorecover settings at tools --> options --> save.
 
Upvote 0
Time is speeding up for you...Test the counter using a pop up window also to make sure it's your code. The other possibility is that Excel's autosave function is also saving and if the file was offset from Excel's autosave by about 2 min then it would seem like it saved every 2 minutes. Instead of 5 for each autosave.
 
Upvote 0

Forum statistics

Threads
1,215,101
Messages
6,123,092
Members
449,095
Latest member
gwguy

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