Data Backup Problems

Automatically Back Up an Excel Workbook with Date and Time Stamps

Emma BrownEmma Brown Nov 22, 2026 869 views

Question details

Automatically create a dated and timed backup copy whenever a shared Excel workbook is saved, without overwriting earlier copies.

Automatically Back Up an Excel Workbook with Date and Time Stamps
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.
Before you start

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.

Solution 1Recommended

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.

1
Save as a macro-enabled workbook

In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). Save the test file in a local folder.

2
Open the workbook module

Open Developer > Visual Basic. In the Project pane, find the test workbook and double-click ThisWorkbook.

3
Add the backup event

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

4
Enable macros and test

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.

5
Test the shared location

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.

Shared-file limitations: The code checks for an existing name and adds a number, but simultaneous saves by different users can still compete for the same filename. Use separate user-specific backup folders or a managed versioning system if concurrent saves must be reliably protected. The example expects a filesystem folder and may not work with a cloud URL.
Free Microsoft Office alternative

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.

Open and edit spreadsheets using familiar workbook toolsWork with Microsoft Excel formats such as XLSXSave separate workbook copies when managing backup versionsUse a free, lightweight alternative for everyday office work
microsoft office alternative - wps office

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.