0

I have to add some shapes to an embedded chart in a worksheet...

no problem with text box

Set Sh = Ch.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
       Left:=left, Top:=top, Width:=width, Height:=height) 
Sh.name = "txtName"```

Apparently no problem with controlbutton

Set Sh = Ch.Shapes.AddFormControl(xlButtonControl, Left:=Ch.Left + left, _
          Top:=Ch.Top + top, Width:=width, Height:=height) 
Sh.name = "btnName"

even if I had to offset the Shape's Left and Top properties value with the respective Chart's properties value in order to move the shape in the right position (first strange thing!!!)

With the code included into a different routine I have to delete these shapes. While I have no problems with textbox

Set Sh = Ch.Shapes("txtName")
Sh.Delete

I can't do the same thing when I try to delete the controlbutton

Set Sh = Ch.Shapes("btnName")
Sh.Delete

During troubleshooting, I found out that, while a new shape is added to the Ch.Shapes collection after using the Ch.AddTextbox method, no new shape is added to the same collection after using the Ch.AddFormControl method. I'm sure enough this is the reason why I can't delete the controlbutton while I can do it for textbox.

Does anybody of you know how to help me? It sounds really strange

7
  • 2
    Hmmm - seems like the form control is tied to the worksheet shapes collection, not the chart.
    – BigBen
    May 22, 2020 at 16:00
  • The button is not "in" the chart - if you move the chart the button does not move with it. That would explain why you had to offset the Top and Left Properties. May 22, 2020 at 16:39
  • @BigBen Even if I do explicitely Ch.Shapes.AddFormControl(xlButtonControl) and I would expect the button into the chart shapes collection, the shape is not there but it is not into the worksheet shapes collection either. I found that button into the worksheet Buttons collection. It sounds as a bug!!
    – Jumpy73
    May 22, 2020 at 19:06
  • It should be in the Worksheet.Shapes collection (tested and was so for me). It would also be a member of the Buttons collection too, yeah. But to @TimWilliams's point, the button is not actually in the chart...
    – BigBen
    May 22, 2020 at 19:08
  • @Tim Williams Yes, that's exactly how it is. Is there a way to do what I want?
    – Jumpy73
    May 22, 2020 at 19:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.