无需其它引用,新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim objEA As Object
Dim var As Variant
Dim n As Long
Set objEA = GetObject(, "Excel.Application")
If objEA Is Nothing Then MsgBox "Error": Exit Sub
Set var = objEA.ActiveSheet.range("A1:B4")
For i = 1 To 4
Debug.Print var(i, 1), var(i, 2)
Next
End Sub
运行结果:
100 red
101 yellow
102 bule
103 green
此Excel表格:A、B列如下。
A | B | |
---|---|---|
1 | 100 | red |
2 | 101 | yellow |
3 | 102 | bule |
4 | 103 | green |