Ankur Kumar
New Member
Hi,
I using VBA code for auto backup of my workup when i close it it will take auto backup of it now i want only latest 10 files will be there and older files will automatically deleted, here is my code please advice how can i do that.
I using VBA code for auto backup of my workup when i close it it will take auto backup of it now i want only latest 10 files will be there and older files will automatically deleted, here is my code please advice how can i do that.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.DisplayAlerts = False
Dim backupfolder As String
backupfolder = "D:\Auto Backup Sales Tracker\Closed\"
ThisWorkbook.SaveCopyAs Filename:=backupfolder & " " & Format(Now, "dd-mmm-yy h-mm-ss") & " " & ActiveWorkbook.Name
ThisWorkbook.Save
Application.DisplayAlerts = True
End Sub
Last edited by a moderator: