Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error on ActiveWorkbook.SaveAs method

Hi there,
I hope there is a really simple answer to this but I have not been abl
to find a simple solution to error trapping the ActiveWorkbook.SaveA
method. When the following command runs (inside a macro) and I selec
'yes' from the dialog box when it says "the file already exists do
want to replace it?" - that's fine. When I select 'no' or 'cancel' th
following error occurs... Runtime Error 1004: "Method 'SaveAs' o
object '_workbook' failed

The method is: (where sWorkBookPath and sFileName are variables for m
path and filename)

ActiveWorkbook.SaveAs Filename:=sWorkBookPath & "\" _
& sFileName & ".txt", FileFormat:=xlText, CreateBackup:=False

How do I stop the macro crashing when I select 'no'

Kindy Regards
And

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Error on ActiveWorkbook.SaveAs method

try putting in either
On Error Resume Next
O

On Error Goto

Or handle the specific erro


On Error GoTo ErrHandler

ErrHandler
If Err.Number = 1004 And
Err.Description = "Method 'SaveAs' of object '_workbook' failed" The
Resume Nex
End If
Make sure you match the description exactly as it shows up in the error

----- cruisy wrote: ----

Hi there
I hope there is a really simple answer to this but I have not been abl
to find a simple solution to error trapping the ActiveWorkbook.SaveA
method. When the following command runs (inside a macro) and I selec
'yes' from the dialog box when it says "the file already exists do
want to replace it?" - that's fine. When I select 'no' or 'cancel' th
following error occurs... Runtime Error 1004: "Method 'SaveAs' o
object '_workbook' faile

The method is: (where sWorkBookPath and sFileName are variables for m
path and filename

ActiveWorkbook.SaveAs Filename:=sWorkBookPath & "\"
& sFileName & ".txt", FileFormat:=xlText, CreateBackup:=Fals

How do I stop the macro crashing when I select 'no

Kindy Regard
And


--
Message posted from http://www.ExcelForum.com


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Error on ActiveWorkbook.SaveAs method

If you always want to save the workbook, this macro won't ask any questions.
It will just save.

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=sWorkBookPath & "\" _
& sFileName & ".txt", FileFormat:=xlText, CreateBackup:=False
Application.DisplayAlerts = False



"cruisy " wrote in message
...
Hi there,
I hope there is a really simple answer to this but I have not been able
to find a simple solution to error trapping the ActiveWorkbook.SaveAs
method. When the following command runs (inside a macro) and I select
'yes' from the dialog box when it says "the file already exists do I
want to replace it?" - that's fine. When I select 'no' or 'cancel' the
following error occurs... Runtime Error 1004: "Method 'SaveAs' of
object '_workbook' failed

The method is: (where sWorkBookPath and sFileName are variables for my
path and filename)

ActiveWorkbook.SaveAs Filename:=sWorkBookPath & "\" _
& sFileName & ".txt", FileFormat:=xlText, CreateBackup:=False

How do I stop the macro crashing when I select 'no'

Kindy Regards
Andy


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error on ActiveWorkbook.SaveAs method

Thanks guys - both solutions worked a treat.
Cheers :)


---
Message posted from http://www.ExcelForum.com/

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
SaveAs method error Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 3 October 6th 09 09:05 PM
Max charactors for 'ActiveWorkbook.SaveAs Filename'? TOMB Excel Worksheet Functions 1 February 16th 05 06:44 AM
Question Using SaveAs Method R3df1sh Excel Programming 1 November 12th 03 07:26 PM
Error Excel: 1004 SaveAs method of Workbook class failed sebastien Excel Programming 0 August 13th 03 09:59 AM
SaveAs method L Buchy Excel Programming 1 July 11th 03 11:27 PM


All times are GMT +1. The time now is 11:45 PM.

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"