N
Neal Zimm
Hi All,
For the first time I had a need to put an object inside a two dimension
variant array.
The proc below was for some initial testing.
I had to code an object test at the line marked with 1.
I was surprised that the 'copy' at line 2. worked.
Can you tell me why?
Thanks.
Neal Z.
Sub Test()
Dim vArray, vArrayB
Dim Row As Long, Col As Long
ReDim vArray(1 To 2, 1 To 2)
Set vArray(1, 1) = ActiveWorkbook
vArray(1, 2) = "abc"
vArray(2, 1) = 24
Set vArray(2, 2) = ActiveSheet
ReDim vArrayB(LBound(vArray, 1) To UBound(vArray, 1), _
LBound(vArray, 2) To UBound(vArray, 2))
For Row = LBound(vArray, 1) To UBound(vArray, 1)
For Col = LBound(vArray, 2) To UBound(vArray, 2)
If Not IsObject(vArray(Row, Col)) Then
vArrayB(Row, Col) = vArray(Row, Col)
Else
'1. for individual items, Set is needed, expected.
Set vArrayB(Row, Col) = vArray(Row, Col)
End If
Next Col
Next Row
' 2. Why does this not 'error out' ?
vArrayB = vArray
End Sub
For the first time I had a need to put an object inside a two dimension
variant array.
The proc below was for some initial testing.
I had to code an object test at the line marked with 1.
I was surprised that the 'copy' at line 2. worked.
Can you tell me why?
Thanks.
Neal Z.
Sub Test()
Dim vArray, vArrayB
Dim Row As Long, Col As Long
ReDim vArray(1 To 2, 1 To 2)
Set vArray(1, 1) = ActiveWorkbook
vArray(1, 2) = "abc"
vArray(2, 1) = 24
Set vArray(2, 2) = ActiveSheet
ReDim vArrayB(LBound(vArray, 1) To UBound(vArray, 1), _
LBound(vArray, 2) To UBound(vArray, 2))
For Row = LBound(vArray, 1) To UBound(vArray, 1)
For Col = LBound(vArray, 2) To UBound(vArray, 2)
If Not IsObject(vArray(Row, Col)) Then
vArrayB(Row, Col) = vArray(Row, Col)
Else
'1. for individual items, Set is needed, expected.
Set vArrayB(Row, Col) = vArray(Row, Col)
End If
Next Col
Next Row
' 2. Why does this not 'error out' ?
vArrayB = vArray
End Sub