Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting CSV to XLS not working

Status
Not open for further replies.

progressive7

Technical User
Jul 25, 2002
33
GB
I am using the below code to convert a csv file to an xls format. it works fine but it will not let me specfiy a file format in the saveas method it justs errors. am i doing anything wrong with the saveas method, btw i am using visual studio

sub convert()
Dim excel As Application
Dim oExcel As Excel.Application
oExcel = New Excel.Application
Dim oBook As Excel.Workbook
Dim input, output As String

On Error GoTo handler


input = "c:\upload\in.csv"
output = "c:\upload\twest.xls"
oBook = oExcel.Workbooks.Open(input)
oBook.SaveAs output, xlExcel9795
oBook = Nothing

oExcel.Quit()
oExcel = Nothing

handler:

MsgBox(Err.Description)

End Sub
 
What error are you getting?

Anyway, try this:

oBook.ActiveWorkbook.SaveAs output, xlExcel9795)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top