Vba 将多个CSV文件导入到一个表中-第一行不';不匹配
我以前使用过下面的代码将多个csv文件从一个文件夹导入Access数据库的一个表中。但是,这次每个文件的第一行包括一个帐号,列标题位于第2行。因此,每个文件的第一行是不同的,并且该代码在“DoCmd.TransferText acImportDelim,strTable,strPathFile,blnHasFieldNames”上失败 如何排除每个文件中的第一行 我尝试将“blnHasFieldNames”更改为False,希望代码能够接受第1行中的任何差异,但这不起作用 将strPath文件设置为字符串、strFile设置为字符串、strPath设置为字符串 Dim strTable作为字符串,strBrowseMsg作为字符串 作为布尔值的Dim blnHasFieldNamesVba 将多个CSV文件导入到一个表中-第一行不';不匹配,vba,ms-access,Vba,Ms Access,我以前使用过下面的代码将多个csv文件从一个文件夹导入Access数据库的一个表中。但是,这次每个文件的第一行包括一个帐号,列标题位于第2行。因此,每个文件的第一行是不同的,并且该代码在“DoCmd.TransferText acImportDelim,strTable,strPathFile,blnHasFieldNames”上失败 如何排除每个文件中的第一行 我尝试将“blnHasFieldNames”更改为False,希望代码能够接受第1行中的任何差异,但这不起作用 将strPath文件设
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = True
strBrowseMsg = "Table Name"
strPath = "FilePath"
If strPath = "" Then
MsgBox "No folder 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 = "Table Name"
strFile = Dir(strPath & "\*.csv")
Do While Len(strFile) > 0
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()
Loop
我得到的错误是(xxxxxx=我使用了这个而不是帐户名)
运行时错误“2391”:
目的表“表名”中不存在字段“xxxxxxxxx”您必须打开文件,删除第一行,保存文件,然后运行导入;或者逐行读取文件,跳过第一行,逐行追加数据
在这两种情况下,都可以使用。您必须打开文件,删除第一行,保存文件,然后运行导入;或者逐行读取文件,跳过第一行,逐行追加数据 在这两种情况下,都可以使用