SaveAs Confict Resolution Help ?

B

Bassman62

Greetings,
Using xl2007
Code:
NewWBName =
Application.GetSaveAsFilename(InitialFileName:="0-Job.xls", _
filefilter:=" Excel 2000-2003 Workbook (*.xls), *.xls,")
If NewWBName = False Then
Range("Date").Activate
Application.ScreenUpdating = True
Exit Sub
Else
NewWB_Setup 'Create a copy of "Report" and convert formulas to
values
' Save new file as 2000-2003 format from version 2007.
NewWB.SaveAs NewWBName, FileFormat:=56, CreateBackup:=False
End If

The above code works well except if the file name already exists and the
user selects 'No' or 'Cancel' from the Conflict Resolution Dialog box.
| A file named '...\0-Job.xls' already exists in this location. Do you want
to replace it?
| Yes / No / Cancel

How can I change my code to handle those selections?
Thanks.
 
B

Bassman62

Sorry, I neglected to state the failure.
The line - NewWB.SaveAs NewWBName, FileFormat:=56, CreateBackup:=False
causes Run-time error'1004': Method 'SaveAs' of object '_Workbook' failed
 
P

Patrick Molloy

you could use
Application.DisplayAlerts = False

which completely avoids the issue -- unfortunatley is doesn't stop the user
saving over files accidentally

You could add a line that has checks if the file exists --- before the file
Save As line, and then handle the result
 
B

Bassman62

Thanks for the reply.
It worked to use the 'Dir' function to test for an existing filename and
then use Application.DisplayAlerts = False to avoid the alert.
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top