【发布时间】:2020-12-23 13:44:54
【问题描述】:
目标是将所有 excel 文件导入一个文件夹中,以单独访问工作表。我找到了这个脚本,但不知道在哪里问
Dim blnHasFieldNames as Boolean
Dim strWorksheet As String, strTable As String
Dim strPath As String, strPathFile As String
' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = False
' Replace C:\Documents\ with the real path to the folder that
' contains the EXCEL files
strPath = "C:\Documents\"
' Replace worksheetname with the real name of the worksheet that is to be
' imported from each file
strWorksheet = "worksheetname"
' Import the data from each workbook file in the folder
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
strTable = "tbl_" & Left(strFile, InStrRev(strFile, ".xls") - 1)
DoCmd.TransferSpreadsheet acImport, _
acSpreadsheetTypeExcel9, strTable, strPathFile, _
blnHasFieldNames, strWorksheet & "$"
' Uncomment out the next code step if you want to delete the
' EXCEL file after it's been imported
' Kill strPathFile
strFile = Dir()
Loop
这里:http://www.accessmvp.com/KDSnell/EXCEL_Import.htm#ImpWktFilesSepTbls
我不知道如何使用代码(把它变成一个宏?)也有可能抓住第三行,例如,把它作为标题?你知道我在哪里可以找到有关它的信息吗?
谢谢
【问题讨论】:
-
我想将.xls文件导入access @Dai
-
DoCmd是 Access 中的一个对象。看看this 的回答。它应该可以帮助你
标签: excel vba ms-access-2010