📊 VBA (Excel)
Backup Workbook with Timestamp
Saves a timestamped copy of the current workbook next to the original, without disturbing the open file.
BackupWorkbookWithTimestamp.bas
Attribute VB_Name = "BackupWorkbookWithTimestamp"
Option Explicit
Public Sub BackupWorkbookWithTimestamp()
Dim wb As Workbook
Dim backupPath As String
Dim ts As String
Set wb = ThisWorkbook
If wb.Path = "" Then
MsgBox "Please save the workbook first.", vbExclamation
Exit Sub
End If
ts = Format(Now, "yyyymmdd-hhnnss")
backupPath = wb.Path & Application.PathSeparator & _
Left(wb.Name, InStrRev(wb.Name, ".") - 1) & "_backup_" & ts & _
Mid(wb.Name, InStrRev(wb.Name, "."))
wb.SaveCopyAs backupPath
MsgBox "Backup saved to:" & vbCrLf & backupPath, vbInformation
End Sub