Hello,
I previously, with help, created a macro to back up my timesheet:
This code worked for a while, but started to get buggy the farther into the year I get (timesheet is for the whole year). My research has got me to be able to write a macro that will search for my back up file, if it doesn't exist it will save it, and if it does exist will delete it.
I am looking to save a new backup copy after deleting it. I thought I was on the right track with this code:
But it seems that the "If FileExist" is not defined. I'm not sure where to go from here. Any help is greatly appreciated.
I previously, with help, created a macro to back up my timesheet:
VBA Code:
Sub Backup_Files()
ActiveWorkbook.SaveCopyAs "D:\Time Sheets\BackUp_" + ActiveWorkbook.Name
End Sub
This code worked for a while, but started to get buggy the farther into the year I get (timesheet is for the whole year). My research has got me to be able to write a macro that will search for my back up file, if it doesn't exist it will save it, and if it does exist will delete it.
VBA Code:
Sub Existing_Backup_File()
Dim FileName As String
FileName = VBA.FileSystem.Dir("D:\Time Sheets\BackUp_" + ActiveWorkbook.Name)
If FileName = VBA.Constants.vbNullString Then
ActiveWorkbook.SaveCopyAs "D:\Time Sheets\BackUp_" + ActiveWorkbook.Name
Else
Kill "D:\Time Sheets\BackUp_" + ActiveWorkbook.Name
End If
End Sub
I am looking to save a new backup copy after deleting it. I thought I was on the right track with this code:
VBA Code:
Sub Existing_Backup_File2()
Dim FileName As String
FileName = VBA.FileSystem.Dir("D:\Time Sheets\BackUp_" + ActiveWorkbook.Name)
If FileName = VBA.Constants.vbNullString Then
ActiveWorkbook.SaveCopyAs "D:\Time Sheets\BackUp_" + ActiveWorkbook.Name
Else
If FileExist("D:\Time Sheets\BackUp_" + ActiveWorkbook.Name) = True Then
Kill "D:\Time Sheets\BackUp_" + ActiveWorkbook.Name
Else: ActiveWorkbook.SaveCopyAs "D:\Time Sheets\BackUp_" + ActiveWorkbook.Name
End If
End If
End Sub
But it seems that the "If FileExist" is not defined. I'm not sure where to go from here. Any help is greatly appreciated.