Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro crashes if option "yes" is not chosen


Hi everyone,

I have a macro called "generate".

The following part of the code if giving me lot of grief:

ActiveWorkbook.SaveAs FileName:=Fname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

If there is a file by the name Fname, then it asks whether it should be
replaced or not. If you click "Yes" it works fine, but if you choose
"No" or "Cancel" it crashes with the following message:

Runtime Error '1004':
Method 'SaveAs' of Object "_Workbook" failed

Any help would be appreciated!

S


--
schoujar
------------------------------------------------------------------------
schoujar's Profile: http://www.excelforum.com/member.php...o&userid=26574
View this thread: http://www.excelforum.com/showthread...hreadid=468109

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Macro crashes if option "yes" is not chosen

It is always a good idea to set up some instructions for errorhandling

You could enter the following line before your saveas statement to ignore
errors and continue code execution

on error resume next

then enter the following after your saveas statement (which will negate the
above instruction)

on error goto 0


"schoujar" wrote:


Hi everyone,

I have a macro called "generate".

The following part of the code if giving me lot of grief:

ActiveWorkbook.SaveAs FileName:=Fname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

If there is a file by the name Fname, then it asks whether it should be
replaced or not. If you click "Yes" it works fine, but if you choose
"No" or "Cancel" it crashes with the following message:

Runtime Error '1004':
Method 'SaveAs' of Object "_Workbook" failed

Any help would be appreciated!

S


--
schoujar
------------------------------------------------------------------------
schoujar's Profile: http://www.excelforum.com/member.php...o&userid=26574
View this thread: http://www.excelforum.com/showthread...hreadid=468109


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Macro crashes if option "yes" is not chosen

You have two choices..... the first will ignore the error thrown by pressing
Cancel and NOT save the workbook. The second will not display the SaveAs
Dialog and the file will always be saved, even if it already exists.


On Error Resume Next
ActiveWorkbook.SaveAs FileName:=Fname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
On Error GoTo 0

OR

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:=Fname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True

--
Cheers
Nigel



"schoujar" wrote in
message ...

Hi everyone,

I have a macro called "generate".

The following part of the code if giving me lot of grief:

ActiveWorkbook.SaveAs FileName:=Fname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

If there is a file by the name Fname, then it asks whether it should be
replaced or not. If you click "Yes" it works fine, but if you choose
"No" or "Cancel" it crashes with the following message:

Runtime Error '1004':
Method 'SaveAs' of Object "_Workbook" failed

Any help would be appreciated!

S


--
schoujar
------------------------------------------------------------------------
schoujar's Profile:

http://www.excelforum.com/member.php...o&userid=26574
View this thread: http://www.excelforum.com/showthread...hreadid=468109



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Macro crashes if option "yes" is not chosen

schoujar,
Which is logically correct.
The .SaveAs method did fail, because you did not give permission to
overwrite, so no save occurred.

You need some error trapping. Look into "On Error" in the Help.

NickHK

"schoujar" wrote in
message ...

Hi everyone,

I have a macro called "generate".

The following part of the code if giving me lot of grief:

ActiveWorkbook.SaveAs FileName:=Fname, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

If there is a file by the name Fname, then it asks whether it should be
replaced or not. If you click "Yes" it works fine, but if you choose
"No" or "Cancel" it crashes with the following message:

Runtime Error '1004':
Method 'SaveAs' of Object "_Workbook" failed

Any help would be appreciated!

S


--
schoujar
------------------------------------------------------------------------
schoujar's Profile:

http://www.excelforum.com/member.php...o&userid=26574
View this thread: http://www.excelforum.com/showthread...hreadid=468109



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
2007 Need macro to auto set option buttons all to "Yes" or "No" Paula Excel Worksheet Functions 1 October 20th 09 08:07 PM
Why is the "zoom" option grayed out in "print preview?" sschreiber Excel Discussion (Misc queries) 0 November 29th 07 04:42 PM
"assign macro" not an option from short menu SteveJ Excel Discussion (Misc queries) 2 May 18th 06 05:55 PM
pictures to work with "data" "sort" option arad Excel Discussion (Misc queries) 1 April 18th 06 09:15 PM
commnd button - when i rt click, "assign macro" isnt an option... kevin[_3_] Excel Programming 1 November 12th 04 09:52 PM


All times are GMT +1. The time now is 12:38 PM.

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

About Us

"It's about Microsoft Excel"