Error on ActiveWorkbook.SaveAs method

  • Thread starter Thread starter cruisy
  • Start date Start date
C

cruisy

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
 
try putting in either
On Error Resume NextOn Error Goto

On Error GoTo ErrHandlerErrHandler
If Err.Number = 1004 And
Err.Description = "Method 'SaveAs' of object '_workbook' failed" The
Resume Nex
End If----- 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
 
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
 
I have the same problem but this solution doesnt allow the file to be saved, it just ignores the error. What now? grrr
 
Back
Top