Delete Shapes using VBA

N

Nikki

Hello...

I would like to delete 10 different shapes off a slide. I want the user to
be able to click on a shape, and that shape disappear. I thought this would
be easy, but it dosent seem to be working out as I planned. Following are
what Ive tried:

Sub Box1()
Dim Box1 As Shape
Box1.Delete
End Sub

I also tried this one and it doesent work either.

Sub Box1 ()
Dim Box1 As Shape
Let Box1.Visible = False
End Sub

Any help that can be offered will be greatly appreciated.

Thanks in advance!
 
D

David M. Marcovitz

Try this:

Sub DeleteMe(oShp as Shape)
oShp.Delete
End Sub

Or change oShp.Delete to oShp.Visible = False if you just want to hide
the shape.

You will need to associate all the shapes with this procedure.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
N

Nikki

Thank you....Thank you...it works perfectly!

If you dont mind me asking...what caused my code (s) not to work properly?

Thanks again!

-Nikki
 
D

David M. Marcovitz

Your code never associated the shape you were clicking with the Delete
method. What you did was Dim a shape object, which creates a new place to
store a shape in PowerPoint. So, you had a variable for a shape, but that
variable was not affiliated with a shape. Thus deleting that shape didn't
so anything.

My code uses a secret trick (shhh, don't tell anyone) that if you have a
shape as the parameter to a procedure, that shape will be associated with
the shape that was clicked. Thus, my procedure not only created the
variable oShp but associated it with the shape that was clicked. Once you
have the variable associated with the shape, you have the power to do
anything with that shape.

By the way, I'm not sure what you are trying to do, but in most cases,
you are probably better off hiding the shape than deleting it. You could
add a procedure that goes through all the shapes on the slide and makes
them all visible again. Once you've deleted them, they are gone.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
N

Nikki

Thanks...I understand now....greatly appreciate it!

I may take your advice on hiding the shapes rather than deleting them. I
will try both methods and see which works best for the presentation.

-Nikki-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top