File Name Exists Error Trap

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I need to stop the file exists from killing my macro and
loop back until my user inputs a filename that is unique.

fname = InputBox("Please Enter File Name", "File Name")Else
ActiveWorkbook.SaveAs Filename:=fname
End If

The >> denotes where I was headed. I am slowly but surely
eating this elephant one bite at a time.

Thanks...

(Hopefully you guys like the taste of Elephant also)
 
Hi
you may try

fname = InputBox("Please Enter File Name", "File Name")
With Application.FileSearch
.lookin = "C:\Temp" 'change this
.Filename = fname
If .Execute then
fname = InputBox("FileName Exists Please Try
Again.", "File Exists")
Else
ActiveWorkbook.SaveAs Filename:=fname
End If
 
One way:

fName = Application.InputBox( _
Prompt:="Please enter file name", _
Title:="File name", _
Type:=2)
Do Until Dir(fName) = ""
If fName = "False" Then Exit Sub 'user clicked Cancel
fName = Application.InputBox( _
Prompt:="FileName Exists Please Try Again.", _
Title:="File Exists", _
Type:=2)
Loop
ThisWorkbook.SaveAs Filename:=fName
 
Back
Top