我想將某些目錄下的所有Excel文件(具有不同的數據和列)導入到MS Access 2010數據庫中,爲每個文件創建新表格。我發現代碼導入到一個表中的文件:自動將不同的excel文件導入MS Access 2010表格
Option Compare Database
Option Explicit
Function DoImport()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = True
' Replace C:\Documents\ with the real path to the folder that
' contains the EXCEL files
strPath = "C:\Documents and Settings\myName\My Documents\Access Test\"
' Replace tablename with the real name of the table into which
' the data are to be imported
strTable = "tablename"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
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
End Function
但我需要每次創建新表。在VBA中可能嗎?
回覆:「如果有人可以提供創建按鈕,模塊和運行的步驟示例,我會非常感激。」 - 哇。如果這不是「太寬泛」,我不知道*是什麼*。 –
我一直在網上瀏覽足夠長的時間,但還沒有找到關於如何創建按鈕並將其與模塊鏈接的示例。我相信它不會花很長時間來快速指導。無論如何,我的主要問題是關於循環創建新表。 –
你想如何命名新表? – HansUp