View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Michael Hardy Michael Hardy is offline
external usenet poster
 
Posts: 2
Default File Exists Killing Workbook_Open()

Frank

Thanks for the tips....

Ok what it does it seems to skip by the Do condition.. Like it is always
true.

So even if the filename chosen exists it still goes the saveas. Then I get
the standard do you want to overwrite message from excel. Of courseif I
choose no the macro dies.


"Frank Kabel" wrote in message
...
Hi Mike
what is your exact problem with the code below. It should work. did you
get an error message?

--
Regards
Frank Kabel
Frankfurt, Germany

Mike wrote:
I have a little code that saves the current file as a
user input name as soon as the file is opened. I am
trying to figure out how to keep the code from breaking
when the user chooses a filename that exists.

The following code was suggested:


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



I haven't been able to get this to work. I am not sure
if I am doing something wrong or not.

Any help with a solution is greatly appreciated.