在VBA中访问数据项目导入CSV文件 [英] Access Data Project Importing CSV File In VBA

查看:209
本文介绍了在VBA中访问数据项目导入CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我遇到一个我的同事开发的旧系统的问题。他们往往有成千上万行代码来做一个简单的事情,如导入csv文件。

Every now and then I come across a problem with an old system one of my colleagues has developed. They tend to have thousands of lines of code to do a simple thing like importing a csv file.

目前vba流程是:


  • 打开excel应用程序

  • 创建新工作表

  • 将csv文件填充到

  • 添加到文件

  • 将工作表另存为新的excel文件

  • 将文件导入访问数据项目sql表。

  • 处理数据

  • open excel application
  • create new worksheet
  • populate the csv file
  • into excel add the header names to the file
  • save the worksheet as a new excel file
  • imports the file into the access data project sql table.
  • Process the data

我想使用的是:


  • 将csv导入表格(类似于获取外部数据函数)

  • 处理数据

我有一个快速搜索,看不到任何简单的方法只是将文件吸入表中。

I have had a quick search and cannot see any easy methods of just sucking the file into the table.

任何帮助都会感激。

感谢

Paul

推荐答案

导入CSV有一种更简单的方法!您可以使用Microsoft Text Odbc Driver。

There is an easier way to import a CSV! You can use the Microsoft Text Odbc Driver.

Sub Import()
   Dim conn as new ADODB.Connection
   Dim rs as new ADODB.Recordset
   Dim f as ADODB.field

   conn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\temp;"
   rs.Open "SELECT * FROM [test.txt]", conn, adOpenStatic, adLockReadOnly, adCmdText

   While Not rs.EOF
      For Each f In rs.Fields
         Debug.Print f.name & "=" & f.Value
      Next
   Wend
End Sub

从选择到插入到与选择相结合。

You change from a Select to an Insert into combined with a select and there you are.

您可以在注册表中的 \\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text

格式:TabDelimited ,CSVDelimited,Delimited(X)其中X =一些char

Format: TabDelimited, CSVDelimited, Delimited(X) where X=some char

FirstRowHasNames:0,1

FirstRowHasNames: 0,1

CharacterSet:OEM ,ANSI

CharacterSet: OEM, ANSI

这篇关于在VBA中访问数据项目导入CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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