Hi can I use a variable to create an object.
I have an array of several names and for each of those names, I would like to create an object.
So I have ("Max", "Tim", "Fred")
and would like to loop through that array with the result that I get something similar to doing it manual like this
Dim Max as CmyClass
Dim Tim as CmyClass
Dim Fred as CmyClass
(if that is very much against all good habits of programming, please let me know how to do that properly)
Thanks
It's not against good programming for as far as I know, but you would need something to store the objects in, which in the case of VBA would be an array or a collection.
something like this
Sub test()
Dim col As Collection
Set col = New Collection
For i = 0 To 4
Dim Name As Class1
Set Name = New Class1
col.Add Name, "test" & i
Next i
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With