将多个* .csv文件导入访问 - 将每个文件导入到单独的表中

时间:2017-05-14 22:30:05

标签: csv ms-access import

我有超过一千个文件要导入ACCESS数据库。 每个文件都需要导入到单独的ACCESS表中。 它需要支持每天导入这些文件,因为,有波兰股票价格,所以每天,晚上08点左右。我正在下载包含1000 * .csv文件的* .zip文件,我需要再次导入它们才能获得今天的价格。

enter image description here

我需要更改一些设置才能正确导入数据。

enter image description here

接下来是: enter image description here

高级设置: enter image description here

看起来如何。

enter image description here

我不知道如何在VBA代码中编写这些高级更改。 在EXCEL中,我可以记录宏,然后使用我选择的设置查看语法,但是可以在ACCESS中执行相同的操作吗?

我在互联网上找到了两个代码。 第一:

  

功能Impo_allExcel()

 Dim my_file As String
 Dim my_path As String

 my_path = "C:\Users\michal\SkyDrive\csv\bossa\mstcgl_csv"
 ChDir (my_path)              'why my_path is inside the brackets??

 my_file = Dir()

 Do While my_file <> ""      'is not empty (<> means not equal to), Excel VBA enters the value into
        'this line above doesn't work, when I'm trying to debug it with F8
   If my_file Like "*.csv" Then
     ' this will import ALL the *.CSV files
     '(one at a time, but automatically) in this folder.
     ' Make sure that's what you want.
    DoCmd.TransferSpreadsheet acImport, 8, "Contacts_AVDC_NEW", my_path & my_file
     ' what this above line says ? please explain.
    End If
    my_file = Dir()     ' what it means?
  Loop
  End Function

第二是:

  

功能Do_Import_from_CSV()

  Dim strPathFile As String
  Dim strFile As String
  Dim strPath As String
  Dim strTable As String
  Dim blnHasFieldNames As Boolean

  ' Change this next line to True if the first row in CSV worksheet has field names
  blnHasFieldNames = True
  ' real path to the folder that contains the CSV files
  strPath = "C:\Users\michal\SkyDrive\csv\bossa\mstcgl_csv"

  ' Replace tablename with the real name of the table into which the data are to be imported
  strFile = Dir(strPath & "*.csv")  'what this line means?

   Do While Len(strFile) > 0
       strTable = Left(strFile, Len(strFile) - 4)
       strPathFile = strPath & strFile
       DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames

   ' Uncomment out the next code step if you want to delete the
   ' EXCEL file after it's been imported
   '       Kill strPathFile

       strFile = Dir()    'what this means?
  Loop
  End Function

请你简要解释一下这些代码, 告诉我他们之间有什么区别, 以及如何将我需要的设置合并到这些代码中, 或者更适合我的那个。 非常感谢。

0 个答案:

没有答案
相关问题