J71
J71

Reputation: 1

Why can't I find any information about object STRUCTURE in Locals window?

I have been trying to understand all of the properties that I see listed in the Locals window in VBE.

Why do some objects have infinitely nested, identical properties? The Range object has a Cells property, which has a Cells property, which has a Cells property, which has a Cells property............ You get the point.

What is this and what is its purpose? Why is it so hard to find the fields that actually CONTAIN the information I'm looking for?

There's an application property of the Range object. You can also find an identical application property as a sublistings of other properties. Why? Are they the same reference? If there are, then why obfuscate the information by putting it there repeatedly? If it's not the same reference then what is it?

I'm looking at the Range Object so I can try find the current region the range encompasses. currentRegion has a currentRegion.....which has a currentRegion.....which has currentRegion.....

currentRegion property, Areas property? No information given on what the difference is between these two and they are synonyms. If the Range.Address properpty exists and it's a simple object type, then why are these other two more complicated?

All I want to do is be able to create an object.....and then actually see what that object is and its values. if anyone can give me some more information, or rather can point me in the direction of documentation that explains this stuff I would be eternally grateful.

Upvotes: 0

Views: 98

Answers (1)

FunThomas
FunThomas

Reputation: 29586

To be honest, it's not really clear what you are asking. And this is not an answer, but it's too long for a comment.

So okay, lets do an example. A Range represents one or several cell(s) of an Excel worksheet. Lots of properties are obvious: Value represents the stored value of the cells, Address the address, Interior with its properties things that define how a cell looks like (color, border...).
Now a cell has a property CurrentRegion. CurrentRegion is a handy property that tells you the surrounding block of cells that contain data. But CurrentRegion is a group of cells and, as we learned, a group of cell is represented as Range. With other words, CurrentRegion is a Range-property of a Range, and therefore has itself a property CurrentRegion. Why not? And what would be the alternative? A class RangeButNotWithCurrentRegion? Or would you set the property CurrentRegion to Nothing if it is the property of a Range that is already used as CurrentRegion? What sense would this make?
The Cells-property of a Range is simply a collection of all cells of that Range. You can address single cells of a Range by either use a single index (Cells(10) would represent the 10th cell within that range) or by using row and column as index (Cells(3, 10) is the cell at row 3 and column 10 of that Range). And again, a single cell is a Range and therefore has a property Cells (and, surprise, a property CurrentRegion). Again: What would be the alternative: A class RangeButWithoutCells?

Another example: The topmost class in VBA is the Application-object. In Excel, the Application-object has a Collection named Workbooks that is a list of all open Workbooks. Now every Workbook has a property Application that points back to exactly this Application-object. Why is it? Sometimes that's handy, for example if you are using Excel-Objects within a Word-VBA macro. And if you think it's superfluent, just forget about it. Don't use it. Until one bright day you will use it and be thankfull that it's there.

If you are looking for the exact information about an object, you can start at the official documentation. And while it's far from perfect, it holds a lot of information that you need. Or press F2 in the VBE to open the object browser. Or put the cursor on a keyword in the code editor (eg CurrentRegion) and press F1 to jump to the official documentation for that class/property. Or search on SO. Or use the search engine of your choice (I will not give the advice to use ChatGPT...)

Update The locals window and it's counterpart, the watch window, are excellent starting points to explore an object, so I guess you are on a good way. If you find something that you already saw (like a CurrentRegion-property of a CurrentRegion-property), just stop clicking on it, it will give you no more information. The Application-Object will always be the same object, and it makes no sense to click on it recursively until the VBE dies an OutOfMemory or StackOverflow error). Just learn that for lots of object, you can go down and up the hierachy. And be aware that not all properties are displayed in the Local window or the object browser. There are hidden properties that are not listed, but you can use them anyhow.

Upvotes: 5

Related Questions