Option Explicit
Public runWhen As Double
Sub AutoSave_Parameters(Optional AutoSaveInterval As Variant = 10)
'Dim AutoSaveInterval As Variant
Dim bProceed As Boolean
Dim currMins As Variant
currMins = Evaluate("'" & ThisWorkbook.Name & "'!AutoSaveInterval")
If IsError(currMins) Then currMins = 10
AutoSaveInterval = InputBox("Please Enter AutoSave Interval in Whole Minutes (1-60): ", Default:=currMins)
'simple validation, bail on error
If Not AutoSaveInterval = vbNullString And IsNumeric(AutoSaveInterval) Then
bProceed = True
If (CInt(AutoSaveInterval) <= 0 Or CInt(AutoSaveInterval) > 60) Then bProceed = False
End If
If Not bProceed Then
MsgBox "Invalid input: Number must be between 1 and 60", vbCritical, "Try Again!"
Else
ThisWorkbook.Names.Add Name:="AutoSaveInterval", RefersTo:=AutoSaveInterval
Call deAutoSave_Initialize(False)
Call AutoSave_Initialize(True)
End If
End Sub
Public Sub AutoSave_Initialize(Optional bPrompt As Boolean = False)
Dim AutoSaveInterval As Variant
AutoSaveInterval = Evaluate("'" & ThisWorkbook.Name & "'!AutoSaveInterval")
If IsError(AutoSaveInterval) Then
MsgBox "You Must Set AutoSave Interval, First"
Else
runWhen = Now() + TimeValue("00:" & AutoSaveInterval & ":00")
Application.OnTime runWhen, "AutoSave_Now", schedule:=True
If bPrompt Then MsgBox "AutoSave Initialized at: " & AutoSaveInterval & " mins."
End If
End Sub
Public Sub deAutoSave_Initialize(Optional bPrompt = True)
On Error Resume Next
Application.OnTime earliesttime:=runWhen, procedure:="AutoSave_Now", schedule:=False
On Error GoTo 0
If bPrompt Then MsgBox "AutoSave Paused"
End Sub
Sub autoSave_Now()
Dim wkb As Workbook
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each wkb In Application.Workbooks
Application.StatusBar = "Saving: " & wkb.Name & " ..."
On Error Resume Next
wkb.Save
On Error GoTo 0
Next wkb
Call AutoSave_Initialize
Application.StatusBar = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Jan Karel Pieterse has an addin called AutoSafe
which doen't alert before saving.
http://www.jkp-ads.com/download.asp
(look for AutoSafe.zip)
It doesn't overwrite the existing workbook when it saves. It saves to a user
selectable folder. And when it's done, it either deletes these backups (or
puts them in the recycle bin). And the user can always restore the backups
from the recycle bin.
Hope that helps.