这是我的代码,但由于某种原因,它在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
答案 0 :(得分:2)
在您的代码中wb
是Excel.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