Autosave workbook

adamsm

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

I'm trying to write a macro code that would auto save my workbook every minute.

Any help on this would be kindly appreciated.

Thanks in advance.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Thanks for the help. But how do I place the last save time in cell A1 of any sheet of the workbook?
 
Upvote 0
Try in the ThisWorkbook module

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("Sheet1").Range("A1").Value = Now
End Sub
 
Upvote 0
Thanks for the help.

But with the line you have given I'm getting debug message that highlights the line of code in the This Workbook Module;

Application.OnTime dTime, "MyMacro", , False

How could I avoid this?

Here is the code I'm using on my This Workbook Module
Code:
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:01:00"), "MyMacro"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime dTime, "MyMacro", , False
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Worksheets("NewMemo").Range("D2").Value = Now
End Sub
And Following is the code I've placed in the standard module
Code:
Public dTime As Date
Sub MyMacro()
Application.ScreenUpdating = False
dTime = Now + TimeValue("00:01:00")
Application.OnTime dTime, "MyMacro"
'YOUR CODE
ThisWorkbook.Save
 Application.ScreenUpdating = True
End Sub
Any help on this would be kindly appreciated.
 
Upvote 0
I don't know why you would get that error. The code I gave you does not call the Before_Close macro where that line of code is.
 
Upvote 0
Code:
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:01:00"), "MyMacro"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime RunTime, "MyMacro", , False
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Worksheets("NewMemo").Range("D2").Value = Time
End Sub

Code:
Public RunTime As Date
Sub MyMacro()
Application.ScreenUpdating = False
RunTime = Now + TimeValue("00:01:00")
Application.OnTime RunTime, "MyMacro"
'YOUR CODE
ThisWorkbook.Save
 Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:
Upvote 0
I would recommend you looking at the link I provided. Generally I tend to not trust the OnTime macros, as they can break and, as far as I'm concerned, are unreliable for a long-term solution.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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