我想将某些目录下的所有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