Self Saving Work Book After One min

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
Hi anyone,

How could I write VBA code that would save the workbook automatically each min without the user having to save manually?

Any help on this would be kindly appreciated.

Thanks in advance.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try this: in a regular module

Code:
Public dTime As Date
Sub MyMacro()
dTime = Now + TimeValue("00:01:00")
Application.OnTime dTime, "MyMacro"
ThisWorkbook.Save
End Sub

In the ThisWorkbook module

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime dTime, "MyMacro", , False
End Sub

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

Save, close and re-open the workbook to test.
 
Upvote 0
Thanks for the reply. How could I modify the code so that each time the workbook gets saved. it displays the saved time in "MySheet" cell A2.

by the way when im trying to close the workbook im getting the debug message 1004
highlighting the line

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime dTime, "MyMacro", , False
End Sub

How can I avoid this and why is this happening?

Any help on this would be kindly appreciated.
 
Upvote 0
Try this

Rich (BB code):
Public dTime As Date
Sub MyMacro()
dTime = Now + TimeValue("00:01:00")
Application.OnTime dTime, "MyMacro"
ThisWorkbook.Save
Sheets("MySheet").Range("A2").Value = Now
End Sub

To prevent the error when trying to close, in the code window press CTRL + G then in the Immediate Window type

Application.EnableEvents=False

and press Enter. Save and close the file. Go back to the Immediate window and type

Application.EnableEvents=False

and press Enter.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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