ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to delete all msoFreeForms on a chart (https://www.excelbanter.com/excel-programming/298009-how-delete-all-msofreeforms-chart.html)

Brian Murphy

how to delete all msoFreeForms on a chart
 
Hello Group,

I have a chart sheet that contains a bunch of msoFreeForm objects, and I want to delete all of them hopefully with one statement.

If I select one and check its Typename I get "Rectangle". But Activechart.Rectangles.Delete does not delete them.

How can I delete them?

Thanks,

Brian Murphy
Austin, Texas


Melanie Breden

how to delete all msoFreeForms on a chart
 
Hi Brian,

Brian Murphy wrote:
I have a chart sheet that contains a bunch of msoFreeForm objects, and I want to delete all of them hopefully with one statement.

If I select one and check its Typename I get "Rectangle". But Activechart.Rectangles.Delete does not delete them.

How can I delete them?


try this:
Dim sh As Shape

For Each sh In ActiveSheet.Shapes
If sh.Type = msoFreeform Then sh.Delete
Next sh

or delete all DrawingObjects:

ActiveSheet.DrawingObjects.Delete

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)


Brian Murphy[_2_]

how to delete all msoFreeForms on a chart
 
Thank you, Melanie.

I will give that a try. I probably can't do
ActiveSheet.DrawingObjects.Delete because of some TextBoxes on the chart.

I suppose the loop will work. Too bad there doesn't appear to be a single
command to delete all of the same type of Shape.

activechart.shapes.SelectAll also selects my textboxes, so no good.

Brian


"Melanie Breden" wrote in message
...
Hi Brian,

Brian Murphy wrote:
I have a chart sheet that contains a bunch of msoFreeForm objects, and I

want to delete all of them hopefully with one statement.

If I select one and check its Typename I get "Rectangle". But

Activechart.Rectangles.Delete does not delete them.

How can I delete them?


try this:
Dim sh As Shape

For Each sh In ActiveSheet.Shapes
If sh.Type = msoFreeform Then sh.Delete
Next sh

or delete all DrawingObjects:

ActiveSheet.DrawingObjects.Delete

--
Regards
Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)





All times are GMT +1. The time now is 05:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com