首页 > 解决方案 > 从 vba 导入 csv 文件而不提供表名

问题描述

我正在尝试将 csv 文件从目录导入访问数据库。我可以导入,但每当我导入文件名时,文件名都会更改,我不想更改文件名。我希望表名与 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 等等,但数据不同..

标签: vbams-access-2010

解决方案


推荐阅读