2011-10-06 61 views
0

我需要一段可以将xls文件转换为csv文件的代码。 我正在使用ms access 2000,并使用VBA在其中编写代码。如何将xls文件转换为访问2000 VBA中的csv文件?

我搜索谷歌和许多解决方案失败。任何帮助表示赞赏。谢谢。

编辑:我试过解决方案,它失败了。它说错误1004不能访问该文件(哪个文件?它没有说)。 enter image description here

我的代码:

Sub XlsToCsv(Fullname As String) 
    filename = Left(Fullname, InStrRev(Fullname, ".")) 

    Set objExcel = CreateObject("Excel.application") 
    Set objExcelBook = objExcel.Workbooks.Open(Fullname) 

    objExcel.Application.Visible = False 
    objExcel.Application.DisplayAlerts = False 

    objExcelBook.SaveAs filename & "csv", 23 

    objExcel.Application.Quit 
    objExcel.Quit 

    Set objExcel = Nothing 
    Set objExcelBook = Nothing 


End Sub 

如何它被称为:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "getInboundCdr", strPathToSave, True 
XlsToCsv (strPathToSave) 

getInboundCdr是查询的名称。

+0

有时它只是冻结。 – lamwaiman1988

回答