Hi,
I am currently using the code below within the "this workbook" section to save a file to one location and also create a backup copy of a file to a different location adding the date to the end of the filename. "filename dd/mm/yy.xls"
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs "C:\Folder Location\Back Up Folder" & "Filename Backup " & Format(Now(), "dd-mm-yy") & ".xls")
ActiveWorkbook.Save
Application.DisplayAlerts = True
This of course generates a new file every day.
What I would like to do is add a little more code to it so that it deletes back up copies of the file which are more than two days old.
ie - if saved on the 5th of the month ("filename 05/mm/yy") it would delete the file called "filename 03/mm/yy" (and anything before) leaving just the filenames with 4th and 5th in the name and so on rolling along daily.
I have tried several examples on here but none seem to work. Can someone please assist.
I am currently using the code below within the "this workbook" section to save a file to one location and also create a backup copy of a file to a different location adding the date to the end of the filename. "filename dd/mm/yy.xls"
Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs "C:\Folder Location\Back Up Folder" & "Filename Backup " & Format(Now(), "dd-mm-yy") & ".xls")
ActiveWorkbook.Save
Application.DisplayAlerts = True
This of course generates a new file every day.
What I would like to do is add a little more code to it so that it deletes back up copies of the file which are more than two days old.
ie - if saved on the 5th of the month ("filename 05/mm/yy") it would delete the file called "filename 03/mm/yy" (and anything before) leaving just the filenames with 4th and 5th in the name and so on rolling along daily.
I have tried several examples on here but none seem to work. Can someone please assist.
Last edited: