In your code wb
is Excel.Application
object, rather than Excel.Workbook
. And Excel.Application
doesn't support SaveAs
method. User this one instead:
Sub convertToXLS()
Dim xlApp As Object
Dim wb As Object
Dim strFile As String
Set xlApp = CreateObject("Excel.Application")
strFile = "C:\path to my file\filename.csv"
Set wb = xlApp.Workbooks.Open(strFile)
With wb
' where 56 is value of excel constant xlExcel8
.SaveAs FileName:=Replace(strFile, ".csv", ".xls"), FileFormat:=56
.Close True
End With
'clean up
Set wb = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub