ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error on ActiveWorkbook.SaveAs method (https://www.excelbanter.com/excel-programming/298505-re-error-activeworkbook-saveas-method.html)

Tim Zych[_8_]

Error on ActiveWorkbook.SaveAs method
 
Whoops, the DisplayAlerts should be TRUE after saving

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


"Tim Zych" wrote in message news:...
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/







All times are GMT +1. The time now is 07:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com