Error when already same name / Macro save as cell contents

N

NeedToKnow

Hi,
I'm getting back to this old question, some problems doesn't go away.

I have this macro and it works fine until invoice has already been saved.
First ofcourse excel wants to know if I want replace earlier file -> no ->
next popup is
"Runtime error 1004
Method 'SaveAs' of object '_Workbook' failed.

How can I get excel to say for ex "file couldn't be saved, check nr or
receiver OR replace older file" This problem doesn't come up if I want
replace old file.

Sub Macro1()

ActiveWorkbook.SaveAs Filename:="D:\SentInvoices\" & Range("C3").Value _
& Range("A8").Value & ".xls", _
FileFormat:=xlNormal, _
Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False

End Sub
 
D

Dave Peterson

If you want to always overwrite your file, you could use:

application.displayalerts = false
'your code to save
application.displayalerts = true

But if you just want to check for an error:

On error resume next
'your code to save
if err.number <> 0 then
msgbox "something went wrong--name, number, permissions, ..."
err.clear
else
msgbox "Saved!"
end if
 
N

NeedToKnow

Thank you again! This site has been a huge help in last 2 months for me.

Life would be sometimes much easier if I would be making files just for my
own use.

"Dave Peterson" kirjoitti:
 

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

Similar Threads


Top