如何将数组定义为文件名在单元格中定义的文件中的列? 我在我正在处理的工作表中为这些单元格定义了一个名称,我也想知道如何在VBA代码中使用它。
答案 0 :(得分:0)
你可以使用这样的东西:
Option Explicit
Sub main()
Dim cell As Range
Dim columnArr As Variant
For Each cell In Worksheets("MySheet").Range("WsNames").SpecialCells(xlCellTypeConstants) '<-- loop through your named range not blank cells
With Workbooks.Open(cell.Value).Worksheets(1) '<-- open workbook after current cell and reference its first worksheet
columnArr = Application.Transpose(.Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Value) '<-- store referenced worksheet column "A" values down to last not empty cell
End Witho
ActiveWorkbook.Close False '<-- close opened workbook
' your code
Next cell
End Sub
更改&#34; MySheet&#34;和#34; WsNames&#34;到您的实际工作表和命名范围名称