Method 'SaveAs' failure

w.goodwater

New Member
Joined
Aug 17, 2007
Messages
1
I have an .xls with multiple worksheets. I have VB script attempting to save one of the worksheets to a new .xls file. When this is run, I get a "Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed" error. My script outputs data to Sheet1. I can save Sheet1 to the new .xls file without problem. But if I add a new sheet, say, Sheet2, and try to save it to the new file, then I receive the above error. I receive this error if I save to a .csv or .txt file, as well.

The line that causes the error is as follows:

Code:
ActiveWorkbook.SaveAs FileName:=strFilename + ".xls", 
                      FileFormat:=xlExcel4, CreateBackup:=False

Any thoughts would be appreciated.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Are you repeating this code for a second sheet? Are you using the same filename? In that case, you will not be able to save a workbook with the name of another open workbook (and you will be overwriting if you could).
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top