Automatically Back Up an Excel Workbook with Date and Time Stamps
Question details
Automatically create a dated and timed backup copy whenever a shared Excel workbook is saved, without overwriting earlier copies.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A shared workbook is saved several times a day and each save should produce a separate backup.
- Observed behavior
- The desired result is a separate timestamped workbook copy for each eligible save.
Save a local test copy as an Excel Macro-Enabled Workbook (.xlsm), and make sure macros are allowed. For server use, confirm that every user can create files in the backup folder.
Create a Timestamped Backup with Excel's BeforeSave Event
Use a workbook event to create a separate copy before each regular save.
This method runs when the workbook is saved, not at scheduled times. The copy contains the workbook state at that moment, which may include a partially completed record.
The example writes copies beside the workbook and skips Save As operations. Test it on a local file before using it on a shared server.
In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). Save the test file in a local folder.
Open Developer > Visual Basic. In the Project pane, find the test workbook and double-click ThisWorkbook.
Paste this code into ThisWorkbook: Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Dim folder As String, baseName As String, ext As String Dim backupName As String, stamp As String Dim dotPos As Long, n As Long If SaveAsUI Or ThisWorkbook.Path = "" Then Exit Sub On Error GoTo BackupFailed folder = ThisWorkbook.Path & Application.PathSeparator dotPos = InStrRev(ThisWorkbook.Name, ".") If dotPos = 0 Then Exit Sub baseName = Left(ThisWorkbook.Name, dotPos - 1) ext = Mid(ThisWorkbook.Name, dotPos) stamp = Format(Now, " yyyy-mm-dd hh-nn-ss") backupName = folder & baseName & stamp & ext n = 1 Do While Dir(backupName) <> "" backupName = folder & baseName & stamp & "-" & n & ext n = n + 1 Loop ThisWorkbook.SaveCopyAs backupName Exit Sub BackupFailed: MsgBox "The backup copy could not be created: " & Err.Description, vbExclamation End Sub
Save and reopen the .xlsm file, enable its macros if prompted and trusted, then save it several times. Open the workbook's folder and verify that each timestamped copy appears and opens correctly.
Move the tested workbook to the intended server folder and ask users to save it. Check that each user has permission to create copies there and that the backup files appear.
Work with Excel-Compatible Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easier to move everyday workbook work between office suites. The Excel-specific VBA backup event above should be tested in Microsoft Excel.

Frequently Asked Questions
Does this macro back up the workbook three times a day?
It creates a copy when an eligible save occurs, not on a fixed schedule. Save the workbook at the desired times, or use a separately designed scheduling approach.
Why was no backup created when I used Save As?
The example intentionally skips Save As when Excel displays the Save As dialog. After saving the workbook under its new name, use Save to trigger a backup.
Can two saves in the same second overwrite a backup?
The code checks for an existing filename and adds a number when needed. However, simultaneous saves by different users can still race, so use separate backup locations or managed versioning for reliable concurrent protection.
What happens if macros are disabled or a user lacks folder permission?
If macros are disabled, the event cannot run. If a user cannot create a file in the workbook folder, the code displays a backup error; the normal save is not canceled.
Can a backup contain an incomplete record?
Yes. The backup reflects the workbook state when the save event runs, so a record that has been only partly entered may also be partly entered in the copy.




