从vba导入csv文件而不提供表名

时间:2019-01-09 13:21:28

标签: vba ms-access-2010

我正在尝试将csv文件从目录导入到Access数据库中。我可以导入,但是无论何时导入,文件名都会更改,并且我不想更改文件名。我希望表名与csv文件相同。我该怎么做呢?这是我的代码: strInitialDirectory =“ S:\”

strPathFile = ahtCommonFileOpenSave(InitialDir:=strInitialDirectory, _
      Filter:=strFilter, OpenFile:=False, _
      DialogTitle:=strBrowseMsg, _
      Flags:=ahtOFN_HIDEREADONLY)

If strPathFile = "" Then
      MsgBox "No file was selected.", vbOK, "No Selection"
      Exit Sub
End If

' Replace tablename with the real name of the table into which
' the data are to be imported
  strTable = strPathFile

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable, strPathFile, blnHasFieldNames

End Sub

如果csv文件名是StudentRecords18 / 19.csv,则表名也应该是StudentRecords18 / 19。我可以在strtable中设置它,但我不想这样做,因为我每个月都会导入不同的数据,因此它将包含带有1的相同表名,以此类推,但最后包含不同的数据。

0 个答案:

没有答案