Reputation: 67
I can select a shape normally with following VBA
ActiveSheet.Shapes(Application.Caller).Select
I want to select a chart and shape the inside the chart. I am not finding line of code.
I tried the following but no success.
ActiveSheet.ChartObjects(Application.Caller).Select
Additional information:
Actually my chart is locked and I want to keep it locked and my sheet it protected(edit object is unchecked). I inserted shape inside the chart. My target is to edit shape inside the chart in locked mode with application.caller. So I can select the shape then I ll be able to edit it
I 'll have more than 10 shapes in chart and shapes are added dynamically with add shape button with random names. so i can target shape with its name. that is why I want to user application.caller to auto select it
Thanks
Upvotes: 0
Views: 769
Reputation: 166885
Sub ChartClick()
Dim cht As Chart, clr
Set cht = ActiveSheet.Shapes(Application.Caller).Chart
cht.Shapes("myShape").Select
' With cht.Shapes("myShape")
' clr = .Fill.ForeColor.RGB
' .Fill.ForeColor.RGB = IIf(clr = vbRed, vbBlue, vbRed)
' End With
End Sub
...assuming your macro is linked to the chartobject and not directly to the shape contained in the chart.
You can (and should) work directly with cht
and not use ActiveChart
. There's almost never any need to select/activate anything in excel in order to work with it.
How to avoid using Select in Excel VBA
Upvotes: 1