我需要的VBA代码汇入指定的电子表格从多个Excel文件到2007年的访问表。 任何人都可以帮忙吗?什么是VBA代码,以从Excel导入文件中选择电子表格到Access 2007表
这是我到目前为止的代码。
Option Compare Database
Option Explicit
Const strPath As String = "C:\Users\person\Documents\files.xlsx"
Dim strFile As String
Dim strFileList() As String
Dim intFile As Integer
Sub Sample()
strFile = Dir(strPath & "*.xls")
strFile = Dir(strPath & "*.xls")
While strFile <> ""
'adding files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
If intFile = 0 Then
MsgBox "No Files Found"
Exit Sub
End If
'going through the files and linking them to access
For intFile = 1 To UBound(strFileList)
DoCmd.TransferSpreadsheet acLink, , _
strFileList(intFile), strPath & strFileList(intFile), True, "A5:J17"
Next
MsgBox UBound(strFileList) & "Files were linked"
End Sub
您对发布的代码有什么问题? –
只需检查这两个 [1]:http://stackoverflow.com/questions/7405261/import-an-excel-worksheet-into-access-using-vba [2]:http://stackoverflow.com/questions/10380312/loop-through-files-in-a-folder-using-vba – Spas