Excel - Specify File Type in Save as (Excel 97-2003)
-
Hi I need to save an Excel file as (Excel 97-2003) For the code below, I have a reference to Microsoft Excel 12.0 Object Library, which I assume is for Excel 2007. When I open a workbook saved as below, I get an error message saying the workbook is not in the expected format. Previously I used a reference to Excel 10.0 which worked fine, but I cannot find that anymore when adding references. I guess I have two choices: a) How do I reference Excel 10.0 Object Library? or b) In the code below, what do I replace "FileFormat As Object" with to specify that the file must be saved as an older Version?
Private Sub ExportExcel() Dim xlApp As New Excel.Application Dim xlBook As Excel.Workbook xlBook = xlApp.Workbooks.Add 'Write stuff to book here... xlBook.SaveAs("MyBook.xls", "FileFormat As Object") xlBook.Close() xlBook = Nothing xlApp.Quit() xlApp = Nothing GC.Collect() End Sub
-
Hi I need to save an Excel file as (Excel 97-2003) For the code below, I have a reference to Microsoft Excel 12.0 Object Library, which I assume is for Excel 2007. When I open a workbook saved as below, I get an error message saying the workbook is not in the expected format. Previously I used a reference to Excel 10.0 which worked fine, but I cannot find that anymore when adding references. I guess I have two choices: a) How do I reference Excel 10.0 Object Library? or b) In the code below, what do I replace "FileFormat As Object" with to specify that the file must be saved as an older Version?
Private Sub ExportExcel() Dim xlApp As New Excel.Application Dim xlBook As Excel.Workbook xlBook = xlApp.Workbooks.Add 'Write stuff to book here... xlBook.SaveAs("MyBook.xls", "FileFormat As Object") xlBook.Close() xlBook = Nothing xlApp.Quit() xlApp = Nothing GC.Collect() End Sub
Found my answer... Use one of the Interop.Excel.XlFileFormat formats Interop.Excel.XlFileFormat.xlExcel8 seems to work fine