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???
 
Actually it does not, since there could be just one "ActiveWorkbook" at a time.
In this case btw, it wouldn't matter if "ThisWorkbook" or "ActiveWorkbook" was used because of the fact, the OnTime method temporarily activates the workbook containing the scheduled macro, launches it, and sets Excel back to its prior state afterwards. Refering to the above code, the active workbook would always be the same as the "ThisWorkbook".
As observed by other forum members, the scheduled code is sometimes executed more often than intended. This is because the scheduled code has to be canceled, preferably at the time the workbook containing the scheduled code is being closed. Otherwise Excel will keep opening the workbook with the scheduled code, will run the code, will close that workbook afterwards, until Excel is completely closed. In order to make canceling possible, the scheduled time has to be stored to be able to let Excel know, which scheduled time has to be cancelled.
Would not recommend you saving all open workbooks using the OnTime method (at such a short interval).
Thank you GWteB for the prompt reply.
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

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