【问题标题】:import multiple CSV file into Access database and save them into different tables based on the file name将多个CSV文件导入Access数据库并根据文件名将它们保存到不同的表中
【发布时间】:2018-10-11 10:31:01
【问题描述】:

我有大约 100 个 CSV 文件,我正尝试将它们导入 Access,然后根据文件名重命名表。

这是我找到的代码,但“tablename”应该是我的文件名。但是,由于我是脚本新手,所以我无法让它工作。

Function Import_multi_csv()

Dim fs, fldr, fls, fl
Set fs = CreateObject("Scripting.FileSystemObject")
Set fldr = fs.getfolder("D:Files\")
Set fls = fldr.files

     For Each fl In fls

      If Right(fl.Name, 4) = ".csv" Then
       DoCmd.TransferText acImportDelim, , "TableName", "D:Files\" & fl.Name, False
      End If

     Next fl

End Function

另外,我的文件中有三列,我希望将第三列作为双精度列导入。

任何帮助将不胜感激。

【问题讨论】:

  • 欢迎来到 Stack Overflow!请不要问双重问题(),因为这些可能需要 2 个完全独立的答案。

标签: ms-access vba ms-access-2010


【解决方案1】:

应该是这样的:

DoCmd.TransferText acImportDelim, , "[" & fs.GetBaseName(fl.Name) & "]", "D:Files\" & fl.Name, False

至于您的第二个问题,您可以创建、保存和使用 导入规范

【讨论】:

    猜你喜欢
    • 2016-08-12
    • 1970-01-01
    • 2020-04-22
    • 2017-02-05
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    相关资源
    最近更新 更多