Home Accessing Object Properties in Array VBA
Reply: 0

Accessing Object Properties in Array VBA

user1645
1#
user1645 Published in July 18, 2018, 4:47 am

I cannot figure out how to access object properties in an array using VBA. I have created an array like:

Dim objectArray(10) as Variant    
Dim counter as Integer            'used to move to next element in array

Next, I declared an object and store it in the array:

Dim object as Variant
objectArray(0) = object           'object stored in array[0]
counter = counter + 1             'increment counter

I want to pass the array to a function.

Call function(objectArray())

That function receives the array of objects like:

Public function(objectArray() as Variant)

So far, it seems to have worked when I have debugged it. My objectArray() seems to contain the object. When I store one object in the array, the debuger shows

objectArray(0)(1,1) .... 'this is in the Watch section of the debugger

I want to access the properties of that object in the first position of the array. That object will contain a name, several values, and a date. I've been trying to access the properties on that object like

Dim separateVar as Variant             'declare new var to hold "name"

separateVar = objectArray(0)(1,1).Value

However, when I run the macro, I get "Some Error Occured, 13, Type Mismatch". Am I accessing the object property values incorrectly?

Any help would be appreciated. Finding articles about accessing objects is easy, but finding ones about accessing their individual properties has been very difficult.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.315754 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO