这似乎是一个相当直接的任务。正如您所解释的,您正在从每个文件中读取相同的单元格位置,因此我会跳过在 Excel 中创建隐藏工作表的想法。从架构的角度来看,我同意 LS_Dev - 保持简单!所有你需要的是
- 一种选择机制,允许您标记和打开(多个)Excel 文件
- 打开和阅读每个选定的 Excel 文件并选择所需数据的例程
- 将数据写入一个(或多个)访问表的代码块
以上三个都可以在一个 Access VBA 模块中巧妙地完成
广告 1。
Sub XLSProcessMulti()
Dim Idx As Long
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Title = "Pick one or more files"
.Filters.Add "Worksheets", "*.xl*", 1
If .Show = -1 Then
For Idx = 1 To .SelectedItems.Count
XLSProcessSingle .SelectedItems(Idx)
Next Idx
End If
End With
End Sub
广告 2。
Sub XLSProcessSingle(FileName As String)
' needs creation of a reference to [Microsoft Excel xx.y Object Library]
Dim WB As Excel.Workbook
Dim Idx As Long
Set WB = Excel.Workbooks.Open(FileName)
' dummy code here just to show a bit how the Excel object can be accessed
Debug.Print WB.Name
For Idx = 1 To WB.Worksheets.Count
Debug.Print WB.Worksheets(Idx).Name
Debug.Print WB.Worksheets(Idx).[A1] ' access a cell by its address enclosed in []
Next Idx
' read sheets, ranges etc. by name or position into local variables
' and store them in Access table(s)
' X = WB.Worksheets(1).[A1] ' by position
' Y = WB.Worksheets("MySecondSheet").[B2] ' by sheet name
' Z = WB.Worksheets(3).Range("MyNamedRange") ' single cell named range
' etc.
WB.Close
End Sub
广告 3。
轮到你 :)