且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用VBA代码将csv文件导入Access?

更新时间:2023-01-21 23:32:35

CSV 代表逗号分隔值。因此,默认导入功能会查找逗号。

"CSV" stands for "Comma Separated Values". Hence, the default import functionality looks for commas.

如果您使用逗号以外的任何内容,请尝试以下操作:

If you're using anything but commas, try this:


  1. 手动开始导入文件。

  1. Start importing the file manually.

在指定设置之后,在单击完成之前,单击高级。 ...

When you have specified the settings, just before clicking Finish, click Advanced...

点击另存为并指定一个名称(或接受Access提议的名称)。

Click "Save As" and specify a name (or accept the one proposed by Access).

记下您选择的名称,让我们说数据导入规范。

Make note of the name you choose, let's say "Data Import Specification".

单击确定两次,然后取消导入。

Click OK twice, then cancel the import.

现在使用您在代码中创建的导入规范:

Now use the import specification that you created in the code:

DoCmd.TransferText acImportDelim ,数据导入规范,表1,D:\ Data.csv,错误

DoCmd.TransferText acImportDelim, "Data Import Specification", "Table1", "D:\Data.csv", False