willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 929
- Office Version
- 365
- Platform
- Windows
Below is part of a code that saves an excel document to a certain directory under a specified name and format. However sometimes a user will create the file manually instead of using the macro but will try and use the macro later causing the below error: file named _____ already exists (see below picture).
Is there a way to save a copy of the document to the same directory without overriding and instead of the below message box, have a new message box that says "file already exists and a copy of the document will be saved". And then save a copy to the same directory without overriding.
Currently if the user says no to replacing it, they get a Run-time error 1004 Method SaveAs of object workbook failed and if they say yes to replacing it, it overrides the original document (which we also do not want either).
Thank you to anyone who can help!
Is there a way to save a copy of the document to the same directory without overriding and instead of the below message box, have a new message box that says "file already exists and a copy of the document will be saved". And then save a copy to the same directory without overriding.
Currently if the user says no to replacing it, they get a Run-time error 1004 Method SaveAs of object workbook failed and if they say yes to replacing it, it overrides the original document (which we also do not want either).
Thank you to anyone who can help!
VBA Code:
Dim path As String
Dim filename As String
path = Workbooks("Customer Concern - Warranty Request Log.xlsm").Sheets("List").Range("I5")
filename = Workbooks("Customer Concern - Warranty Request Log.xlsm").Sheets("List").Range("G1")
ActiveWorkbook.SaveAs filename:=path & filename & ".xlsx", FileFormat:=51
Range("A1").Select
Kill Workbooks("Customer Concern - Warranty Request Log.xlsm").Sheets("List").Range("I7")
Windows("Customer Concern - Warranty Request Log.xlsm").Activate
Sheets("List").Select
Set Target = Range("G16")
If Target.Value = "AeroDept" Then
Call RR_Warranty
Call Warranty_Email
End If
Windows("Customer Concern - Warranty Request Log.xlsm").Activate
Worksheets("List").Visible = False
Sheets("CC Database").Select
Case vbNo
GoTo Quit:
End Select
Quit:
End Sub
Private Sub Transfer_CC()
Dim fso
Dim Source_File As String
Dim Source_Folder As String
Dim Destination_Folder As String
Source_File = Workbooks("Customer Concern - Warranty Request Log.xlsm").Sheets("List").Range("M1").Value & ".xlsx"
Source_Folder = Workbooks("Customer Concern - Warranty Request Log").Sheets("List").Range("I8").Value
Destination_Folder = Workbooks("Customer Concern - Warranty Request Log.xlsm").Sheets("List").Range("I5")
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile (Source_Folder & Source_File), Destination_Folder, True