Can I tell what properties an object has in Watches window?

Viewed 35

I'm trying to get the chart count in a sheet. I use the following line of code but Excel doesn't like it, saying the property is not supported. However, in the Watches window, count is listed under Sheets(1).ChartObjects. My question is why Excel says "property not supported" when Watches window shows the property. I always thought I could see what properties an object has by looking in the Watches window. Not so?

Sheets(1).ChartObjects.Count

enter image description here

2 Answers

Sheets(1).ChartObjects.Count must definitely return the number of charts. Even if no chart exists. It would return 0.

In your case the error is raised because the code line does not make sense...

Try:

Debug.print Sheets(1).ChartObjects.Count
MsgBox Sheets(1).ChartObjects.Count

VBA needs to somehow return the property value and it cannot...

Watches Window does its job, but it is a matter of something else.

Count is a property. Thus when you write

Sheets(1).ChartObjects.Count

VBA will treat this as a Property Let statement, i.e. assignment of a value to Count because you are not assigning the value from count to a variable or using it in an expression. Now, because Count has no Let property, VBA won't find such a property hence the error.

Related