将多个CSV文件导入Microsoft Access 2016

时间:2017-11-03 14:49:33

标签: csv ms-access ms-access-2016

我有多个非常相似的CSV文件保存在同一个目录中,我想一次性导入Access。我希望他们都去一张桌子。

我做了一些研究,自学了一些VBA基础知识并最终得到了这个脚本:

Public Function Import()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean


blnHasFieldNames = True

strPath = "C:\Downloads\models"

strTable = "ModelData"

strFile = Dir(strPath & "*.csv")
Do While Len(strFile) > 0
      strPathFile = strPath & strFile
      DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
            strTable, strPathFile, blnHasFieldNames


      strFile = Dir()
Loop

End Function

尝试运行宏没有做任何事情,我被困在哪里向前推进。

我按照相同的指南在这个快速分钟视频中运行了一个宏:https://www.youtube.com/watch?v=mXdn7ca2BX4

我希望我在某处错过了一点......

另外,我认为我需要以文本格式导入每一列,因为没有正确返回日期/时间数据。

我试图在这里遵循一些类似的问题但是我并不真正了解VBA编码:/

任何帮助都会很棒!谢谢!

1 个答案:

答案 0 :(得分:0)

对于CSV文件文件,您必须使用DoCmd.TransferText:

DoCmd.TransferText TransferType:=acImportDelim, _
                   TableName:=strTable, _
                   FileName:=strPathFile, _
                   HasFieldNames:=True
相关问题