ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   XLBook.Save fails in Excel 2007 (https://www.excelbanter.com/excel-programming/378248-xlbook-save-fails-excel-2007-a.html)

D.P. Roberts

XLBook.Save fails in Excel 2007
 
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.P. Roberts

XLBook.Save fails in Excel 2007
 
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.

"D.P. Roberts" wrote in message
...
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?






All times are GMT +1. The time now is 03:54 AM.

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