尝试将打印行更改为:
Debug.Print vArray(1, 1)
以下是您可以循环访问它们的方法:
Sub Test()
Dim vArray() As Variant
vArray = Range("myRange")
Dim i As Long
For i = LBound(vArray, 1) To UBound(vArray, 1)
Debug.Print vArray(i, 1)
Next
End Sub
*编辑*
要使用“Book2”而无需激活它,您可以这样做:
Sub Test()
Dim vArray() As Variant
Dim rng As Range
Dim wbk As Workbook
Set wbk = Excel.Application.Workbooks("Book2.xls")
Set rng = wbk.Worksheets("Sheet1").Range("myRange")
vArray = rng
Dim i As Long
For i = LBound(vArray, 1) To UBound(vArray, 1)
Debug.Print vArray(i, 1)
Next
End Sub
要从另一本书打开 book2,请将第 5 行更改为:
Set wbk = Excel.Application.Workbooks.Open("C:\Users\myname\Desktop\Book2.xls")