MS Access将.csv转换为.xls

这是我的代码,但由于某种原因,它在saveas行(对象不支持等)失败。

Sub convertToXLS() Dim wb As Object Set wb = CreateObject("Excel.Application") Dim strFile As String strFile = "C:\path to my file\filename.csv" wb.Workbooks.Open (strFile) With wb .SaveAs FileName:=Replace(strFile, ".csv", ".xls") .Close True End With Set wb = Nothing End Sub 

在你的代码中, wbExcel.Application对象,而不是Excel.Workbook 。 而Excel.Application不支持SaveAs方法。 用户这个代替:

 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