Save .XLS to .CSV

Hollywood

New member
Joined
Sep 10, 2004
Messages
1
I have accomplished the feat of opening a Excel spreadsheet and now I want to save that sheet as a .csv. I do not want to simply rename the extension, but rather save it as a comma-separated file so I can parse the data inside it. One other twist it that I have to run this on systems with\without Excel installed and also different versions. (2000\2002\2003)

Heres what I have:

Dim Excelapp As Excel.Application
Dim ExcelWS As Excel.Worksheet This is the sheet

Excelapp.Workbooks.Open(FileName:=strXLSPath)
Check for later versions.
If Val(Excelapp.Application.Version) >= 8 Then
ExcelWS = Excelapp.ActiveSheet
Else
ExcelWS = Excelapp
End If

Open specified worksheet
ExcelWS = Excelapp.Worksheets(2)

ExcelWS.SaveAs(strPath & strCSVFile, Excel.XlFileFormat.xlCSV)


Close without saving
Excelapp.ActiveWorkbook.Close(False)
Excelapp.Quit()
ExcelWS = Nothing
Excelapp = Nothing

The bold code works on 2002 versions, but not on other versions. Is there an equivilent that will work on all versions?

TIA,
Hollywood
 
For sure this should fun on 2002 and 2003. The syntax for Excel 2000 (XL 9.0) is also the same. Unfortunately getting any .Net code to run on 2000 or below is a whole other ball of wax... You may have to switch to late binding to get it to work for XL 9.0 and below. There are no PIAs for it nor support really of any kind that I know of. But people have had success with late binding with both XL 9.0 and 8.0.

Personally, Id much rather do this in VBA or even VB 6.0 if you need compatiblity below Excel 2002...
 
Back
Top