• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 612
  • Last Modified:

Excel - Remove shapes

I have added shapes to my worksheet from VBA using the following code:

With tasksheet.Shapes

With .AddShape(msoShapeRectangle, tlh1, tlh2, brh1, brh2)

With .Fill
     .ForeColor.RGB = RGB(200, 200, 200)
     .BackColor.RGB = RGB(200, 200, 200)
     .Patterned msoPattern50Percent
End With

End With

End With

This appears to work well, but I need to be able to remove all the shapes on the worksheet using a button_click().

I have also placed textboxes using addtextbox(etc..) so I must remove these at the same time.

hope someone can help.
Thanks

/Bob
0
BobR
Asked:
BobR
  • 2
1 Solution
 
vboukharCommented:
You can use something like that:
for each c in activesheet.shapes
 c.delete
next
It removes texboxes too
0
 
antratCommented:
Hi BobR

This one line should do it


ActiveSheet.DrawingObjects.Delete

good luck


antrat


0
 
BobRAuthor Commented:
Thanks for the solutions, but I ommitted one item.
On the worksheet are several buttons and both your solutions remove them as well, can you change the solution to leave these buttons on the worksheet.
Sorry for the ommission.
/Bob
0
 
vboukharCommented:
Try this one:
For Each c In ActiveSheet.Shapes
 If c.Type <> msoOLEControlObject Then
  c.Delete
 End If
Next

Good luck!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now