Arrays have to be type Variant. Is there a way to fill an array with objects, some kind of type conversion that will work?
Sub foo()
Dim strarrNames() As String
ReDim strarrNames(0 To 1)
strarrNames(0) = "Glory"
strarrNames(1) = "Colin"
End Sub
Sub foo()
Dim objarrNames() As Object
ReDim objarrNames(0 To 1)
Set objarrNames(0) = Worksheets(1)
Set objarrNames(1) = Workbooks(2)
End Sub
Sub showArr()
Dim Arr(2)
Arr(0) = 1
Arr(1) = "a string"
Set Arr(2) = Application
Debug.Print Arr(0) & ", " & Arr(1) & ", " & Arr(2).Caption
End Sub
I've got some code working that links controls with code, but I need it to work dynamically. Arrays have to be type Variant. Is there a way to fill an array with objects, some kind of type conversion that will work?
ADVERTISEMENT
I'm having problems getting the array to survive between separate subs in a class module because I can't declare the array at module-level (compile error) and I have no idea how to make it into a property.
Could anybody help me out with that?
Public MyCollection As New Collection
Public Sub Test()
Userform1 Show
End Sub