导入带有分隔符的文本 [英] Importing a text with separators

查看:82
本文介绍了导入带有分隔符的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动添加新的文本文件,这些文件都具有相同(已知)的布局.

I am trying to automate the adding of new text files, which all have the same (known) layout.

列使用制表符(TAB 按钮)分隔.我的问题是,是否可以在 VBA 中执行此操作?比如,在用于导入文本文件的访问向导中?

The columns are separated using tabs (the TAB button). My question is, is it possible to do this in VBA? Like, in the access wizard for importing text files?

我在 VBA 中使用 DoCmd.TransferText 方法

I am using the DoCmd.TransferText method in VBA

推荐答案

您需要通过一次向导来制作规范文件.要执行此操作,请像往常一样导入文本文件,但在深入了解向导之前,请单击左下角的高级..."按钮.这是您制作规范文件的地方.

You'll need to go through the wizard once to make your specification file. TO do this import your text file like normal but before you get too deep into the wizard click on the bottom left, the "Advanced..." button. This is where you make your spec file.

使所有这些列与您的输入文件、数据类型和所有内容相匹配.如果您正在使用,请务必选择 {tab} 字段分隔符和适当的文本限定符.

Make ll these columns match your input file, data types and all. Be sure to select the {tab} field delimiter and the appropriate text qualifier if you are using one.

保存您的规范(稍后可以通过返回同一屏幕并单击Specs...然后保存旧的来对其进行编辑)

Save your spec (which can later be edited by coming back to this same screen and clicking Specs... then saving over your old one)

现在你可以像这样在 VBA 中使用

Now you can use in VBA like this

DoCmd.TransferText acImportDelim, "your spec name", "destination table name", sourceFilePath

有一个参数 HasFieldNames,您必须根据您的文件决定它是 true 还是 false.

There is a parameter HasFieldNames that you'll have to decide if it is true or false based on your file.

这篇关于导入带有分隔符的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆