Divadog
03-03-2025, 08:06 AM
I need help to get the appended Excel macro to work. The macro should back up the active workbook to a folder on one of my hard drives every ten minutes. Each save should have a different file name. I don't want to use the Microsoft Excel autorecover feature as I don't trust the cloud in any way. Also, I'm making a lot of edits where errors may not be apparent for quite a while. I may need to redo 30 minutes of editing.
i cobbled this macro together from various Excel autosave macros I found on the Internet. The macro will run, but it is not saving the workbook. No error is given. I cannot determine what code is failing to make the save statement(s) run.
I would be very grateful to any forum member who can correct my code.
Also, fairly often I leave my workbooks open for quite a while but do no work on them. So, during these 'down' periods there is no need to for automatic backups: The workbook is unchanged. I only want to have a backup when I have made changes to a workbook.
So, I'm looking for a line(s) of code that would only execute an automatic save when I resume working on it. Kind of like a WORKBOOKISACTIVE function (I doubt if there is one) that could go in an if statement:
IF WORKBOOKISACTIVE then
. . . start countdown for savings the workbook after 10 minutes has elapsed.
My thanks in advance for your help and suggestions.
Here is my macro:
Private Sub StartTimer()
Dim SavedFileVersion As Integer
SavedFileVersion = 0 'Set File version number to 0
m_dtNextTime = Now + m_dtInterval
Application.OnTime m_dtNextTime, "MacroName"
End Sub
Public Sub MacroName()
On Error GoTo ErrHandler:
Dim StrPath As String
Dim StrExt As String
Dim NewFileName As String
Dim Interval As Integer
Dim SavedFileVersion As String
SavedFileVersion = SavedFileVersion + 1 'increase the file name version number by 1
StrPath = "H:\Miscellaneous\Computing\Excel AutoSave Spreadsheets" 'Folder to save workbook
StrExt = CStr(SavedFileVersion) & ".xlsm" 'Workbook extension
NewFileName = StrPath & StrExt 'Workbook file name
StartTimer
Exit Sub
ErrHandler:
' Handle errors, restart timer if desired
End Sub
Public Sub Disable()
On Error Resume Next ' Ignore errors
Dim dtZero As Date
If m_dtNextTime <> dtZero Then
' Stop timer if it is running
Application.OnTime m_dtNextTime, "MacroName", , False
m_dtNextTime = dtZero
End If
m_dtInterval = dtZero
End Sub
i cobbled this macro together from various Excel autosave macros I found on the Internet. The macro will run, but it is not saving the workbook. No error is given. I cannot determine what code is failing to make the save statement(s) run.
I would be very grateful to any forum member who can correct my code.
Also, fairly often I leave my workbooks open for quite a while but do no work on them. So, during these 'down' periods there is no need to for automatic backups: The workbook is unchanged. I only want to have a backup when I have made changes to a workbook.
So, I'm looking for a line(s) of code that would only execute an automatic save when I resume working on it. Kind of like a WORKBOOKISACTIVE function (I doubt if there is one) that could go in an if statement:
IF WORKBOOKISACTIVE then
. . . start countdown for savings the workbook after 10 minutes has elapsed.
My thanks in advance for your help and suggestions.
Here is my macro:
Private Sub StartTimer()
Dim SavedFileVersion As Integer
SavedFileVersion = 0 'Set File version number to 0
m_dtNextTime = Now + m_dtInterval
Application.OnTime m_dtNextTime, "MacroName"
End Sub
Public Sub MacroName()
On Error GoTo ErrHandler:
Dim StrPath As String
Dim StrExt As String
Dim NewFileName As String
Dim Interval As Integer
Dim SavedFileVersion As String
SavedFileVersion = SavedFileVersion + 1 'increase the file name version number by 1
StrPath = "H:\Miscellaneous\Computing\Excel AutoSave Spreadsheets" 'Folder to save workbook
StrExt = CStr(SavedFileVersion) & ".xlsm" 'Workbook extension
NewFileName = StrPath & StrExt 'Workbook file name
StartTimer
Exit Sub
ErrHandler:
' Handle errors, restart timer if desired
End Sub
Public Sub Disable()
On Error Resume Next ' Ignore errors
Dim dtZero As Date
If m_dtNextTime <> dtZero Then
' Stop timer if it is running
Application.OnTime m_dtNextTime, "MacroName", , False
m_dtNextTime = dtZero
End If
m_dtInterval = dtZero
End Sub