I have an excel file, which creates a new excel file if a given condition is satisfied. The new file will be saved in the same location of the original file and the new file name will be according to a cell content in the parent file.
The problem that I need to solve is that, I need a message box to be appeared while the parent file is trying to save the new file and location has already a file in that name.
So, basically I want the VBA codes to search whether a file in the similar name is existing the current location, if not save the new file or else return a message
My parent file codes are given under
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheet1.Cells(2, 1) = Sheet1.Cells(3, 6) Then
ActiveWorkbook.Close SaveChanges:=True
Else
Dim fn As String
fn = ActiveWorkbook.path & "\" & Sheet1.Cells(3, 6) & ".xls"
ActiveWorkbook.SaveAs fileName:=fn
ActiveWorkbook.Close SaveChanges:=False
End If
End Sub
Bookmarks