如何使用 access VBA 定义要从 excel 导出到 MS access table 的列数?

How to define the number of columns to be exported from excel to MS access table using access VBA?

我正在导入 excel 工作表 TableName.Test 以访问 table,并且该功能运行良好。但是,所有空列也被导入超过最大访问数 table 列。请告诉我如何仅导出 excel 的前 10 列以进行访问。

Public Sub ImportExcelSpreadsheet(fileName As String, tableName As String)
'Dim strXls As String
'strXls = CurrentProject.Path & Chr(92) & "BI_DataBase.xls"
 tableName = "MiddleTable"
 DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, tableName, fileName, True, "Test!"
 Exit Sub

您必须为您的列指定 [Range] 参数。使用 "Test!A:J" 表示从 sheet Test 导入列 A 到 J。当您未指定列时,它占用的最大列容量为 MS-Access table which is limit to 255.