我之前设法将csv文件导入到ms访问表中,但这是通过事先指定表列来匹配csv来完成的。我打算处理一个更大的csv文件,并想知道是否可以以编程方式输入表列。
Private Sub Import_Click()
'import excel file
'delete current table data
With CurrentDb
CurrentDb.Execute "DeleteTableData"
End With
'import
Dim f As Variant
Set f = Application.FileDialog(3)
'set dialog title
With f
.Title = "Choose File"
f.AllowMultiSelect = False
'Use the Show method to display the File Picker dialog box and return the
user's action.
'The user pressed the action button.
If .Show = -1 Then
For Each f In .SelectedItems
'import into table
DoCmd.TransferText acImportDelim, , "[Table1]", f, True
Next f
MsgBox "File Imported"
Else
'Show if Canceled is selected in a message box
f = "No File Selected to Import."
MsgBox f
End If
End With
DoCmd.SetWarnings True
DoCmd.Hourglass False
End Sub
用户可以选择他们想要的任何csv文件,然后单击它将导入它并将数据输入到表格中。