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.
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,793
Office Version
  1. 2019
Platform
  1. Windows
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).
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,610
Members
414,080
Latest member
penguin23

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
Top