Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 47
Default Error when already same name / Macro save as cell contents

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

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Error when already same name / Macro save as cell contents

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



NeedToKnow wrote:

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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 47
Default Error when already same name / Macro save as cell contents

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:

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



NeedToKnow wrote:

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


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear Contents Of Cell If Value = 0 or Error carl Excel Worksheet Functions 4 July 9th 07 04:54 PM
Save using Macro but test to see if an error appears on spreadshee jfaz Excel Discussion (Misc queries) 1 September 18th 06 04:38 PM
How to save file in a macro taking new name from cell contents? LowIQ Excel Discussion (Misc queries) 3 May 31st 06 10:52 PM
Macro that looks at cell contents teamwill Excel Discussion (Misc queries) 2 January 10th 06 01:38 AM
Macro to remove contents of cell and move all other contents up one row adw223 Excel Discussion (Misc queries) 1 July 1st 05 03:57 PM


All times are GMT +1. The time now is 05:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"