The following code works great to prompt the user for a saveas file name except when the filename already exists and the user answers “no” to the question “A file named ‘C:Fieldtools1235.xls’ already exists in this location. Do you want to replace it? Yes, No, Cancel”
All works well if we answer yes or Cancel, but if I answer “No” I get the the following debug message:
Run time error 1004, Method of “SaveAs” of object ‘_Workbook failed.
The debug brings me to this line in the above code:
ActiveWorkbook.SaveAs Filename:=DataFileName
How do I get the “No” click of the button to return “false” as the filename. (Or remove the No as an option?)
Thanks for any help you may have!
DataFileName = Application.GetSaveAsFilename(TractNo & “.xls”, “Excel Files (*.xls),.xls,All Files, *.*”)
If DataFileName “False” Then ‘if user didn’t press cancel
ActiveWorkbook.SaveAs Filename:=DataFileName
End If