Simon has attended:
Excel VBA Advanced course
Excel VBA object properties
How can I cycle through the properties of an object - names and values - e.g. when I have set up a new class object, to test it I would want to debug.print all the properties and the values they hold, without needing to specifically enter them
RE: Excel VBA object properties
Hi Simon, thanks for your query. Actually, the best way to do this would be to use the Locals window (View - Locals Window). This will show what is being held in memory at each line of code, so once you set an object variable to hold an instance of your class object (e.g. Set myObjectVariable = New clsmyclassobject) and then step through your code (F8) you'll see your object dropped into memory and the Locals Window will give you a plus sign next to the name of the object. Clicking on that plus sign expands a list of all the properties of that object and what values they hold at that point in the code. Try this out and see how you get on.
Hope this helps,
Anthony
RE: Excel VBA object properties
Thanks Anthony.
Yes I believe that would work but really I was trying to get at how I could access and loop through the "collection of properties" - if you like - from my code.
Is that something it's possible to do?
Thanks for the tip though as I think that will be useful to me anyway....
Cheers
Simon
RE: Excel VBA object properties
Hi Simon. There's no index number for the properties of objects, so you can't loop through them like that. One way you might want to consider is to stick the property names into an array when you build the class object and loop through that array.
Hope this helps,
Anthony