Saveas

  • Thread starter Thread starter Dale Levesque
  • Start date Start date
D

Dale Levesque

I'm using the following code to save a file.

ActiveWorkbook.SaveAs FileName:=fs_Path & "Data\" & ls_SmallSaveName &
".xls", FileFormat:= _
xlNormal, Password:="", writerespassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False

A dialog box comes up if the file already exists asking whether to replace
it.

How can I handle it if the user says 'No'?

Thanks,

Dale
 
Hi
to save in all cases try
application.displayalerts=false
ActiveWorkbook.SaveAs FileName:=fs_Path & "Data\" &
ls_SmallSaveName &
".xls", FileFormat:= _
xlNormal, Password:="", writerespassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
application.displayalerts=True
 
Dale,

What do you mean by handle it? If you are happy that the user can say no,
then there is nothing more to do.If you are not happy with this and insist
that it is saved, you could precede the SaveAs with

Application.DisplayAlerts = False

and then the question doesn't get asked. Reset to True afterwards.
 
No Frank, I'd like to close the current workbook without saving as the
specified name when the user selects 'No'.

Dale
 
By handle it I mean that if the user selects 'No'. The sub exits gracefully
without an error message.

Dale
 
Test for the existence of a file before you attempt to save it.
Put up a msgbox to query the user and react to the result.


If dir("c:\mypath\myfile.xls") <> "" then
ans = Msgbox( "Overwrite", vbYesNo)
if ans = vbNo then
exit sub
else
kill "c:\mypath\myfile.xls"
End if
End if

' do the save
 
Thanks very much. I was hoping that there would be some kind of return value
or way to trap the saveas method error but your suggestion will work nicely.

Dale
 

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

Back
Top