M.P.
M.P.

Reputation: 272

Why activate chart first?

Don't know if it is the best title for my question... :)

I have a chart in excel. I want to use SetElement.

If i use this code it gets an error (Object doesn't support this property or method):

Dim Graphics As Worksheet
Set Graphics = Worksheets("Graph")
Graphics.ChartObjects("Chart 1").SetElement (msoElementChartTitleNone)

If i use this code it works well:

Dim Graphics As Worksheet
Set Graphics = Worksheets("Graph")
Graphics.ChartObjects("Chart 1").Activate
ActiveChart.SetElement (msoElementChartTitleNone)

Can someone explain why the first option isn't working? It is still the same command on the same object?

Upvotes: 0

Views: 117

Answers (1)

to StackOverflow
to StackOverflow

Reputation: 124696

It's the same command (method) on a different object (ChartObject vs Chart).

Try:

Graphics.ChartObjects("Chart 1").Chart.SetElement ...

Upvotes: 2

Related Questions