XLBook.Save fails in Excel 2007

D

D.P. Roberts

I have several vb scripts that copy data from csv files to xls files and the
XLBook.Save method worked fine in previous versions of Office. However, in
Excel 2007 I get a "Save method of Workbook class failed" error when
attempting to execute the following:

Dim XL, CSVBook, XLBook
Set XL = CreateObject("Excel.application")
Set CSVBook = XL.Workbooks.Open("CSVfile.csv")
Set XLBook = XL.Workbooks.Open("XLSfile.xls")
CSVBook.Worksheets(1).Range("A1:C100").Copy
XLBook.Worksheets("data").Select
XLBook.Worksheets("data").Range("A1").PasteSpecial
XLBook.Worksheets("data").Range("E1").Select
CSVBook.Worksheets(1).Range("D1").ClearContents
CSVBook.Close False
XLBook.Save ****ERROR HAPPENS ON THIS LINE****
XL.Visible = True


Does anyone know if the syntax has changed or if Excel 2007 uses a different
method?
 
D

D.P. Roberts

I got it working and here's the solution if anyone is interested:

My source xls file ("XLSfile.xls") was created in Excell 2003 so this was a
simple version compatibility issue. To fix, open the xls file with Excel
2007 and save it. Then run the vbs file again - the XLBook.Save method
should work fine now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top