How make shapes invisible in MANY slides?

G

Gato_de_Botas

I have some shapes that I need start invisible in many slides. I am using the
expression ActivePresentation.Slides (6).Shapes ("name of the
shape").Visible=False
My question is: instead the number 6, what I should write to work in many
slides? I tried (6,7,8) but it does not work. Also I tried (6.7.8) and the
same result.

Maybe some kind of name like "all", and then the shape will become invisible
in all slides. Is that possible?
thanks!
 
D

David Marcovitz

I don't think there is anything you can put in the parentheses to do
this in one shot, but you have a few choices. If you are talking about
just slides 6, 7, and 8, it should take all of 4 seconds to copy your
line of code and paste it a couple of more times and then change the 6
to 7 on one line and the 6 to 8 on another.

If you are talking about a larger range of slides, you could do it with
a loop. To do it for all slides, you would do something like (I haven't
tested this code so it might contain typos):

For i = 1 To ActivePresentation.Slides.Count
ActivePresentation.Slides(i).Shapes ("name of the shape").Visible=False
Next i

That will cover all the slides. If you want to just do 6, 7, and 8 with
this method, you could do

For i = 6 To 8
ActivePresentation.Slides(i).Shapes ("name of the shape").Visible=False
Next i

--David
 
S

Shyam Pillai

In addition to Steve's suggestion, you can also use this hide all shapes on
the slide:
ActivePresentation.Slides(1).Shapes.Range.Visible=False

or even build your own range, where numbers represent the z-orderposition of
the shapes.
'To hide the 1st and the 5th shape on the slide.
ActivePresentation.Slides(1).Shapes.Range(array(1,5)).Visible=false

Regards,
Shyam Pillai

Image Importer Wizard: http://skp.mvps.org/iiw.htm
 
G

Gato_de_Botas

Thank you, David! Wonderful your book, I bought it and reading at the moment!
I recomend the book to everybody that wants to improve in VBA in Powerpoint.

The expression:

For i = 6 To 20
ActivePresentation.Slides(i).Shapes ("name of the shape").Visible=False
Next i

is working OK. The shape is in the range 6-20 of slides. I found that if I
write 6 To 21, the expression does not work, because the shape is not in the
slide 21.

The first expression you sugest did not work:
For i = 1 To ActivePresentation.Slides.Count
ActivePresentation.Slides(i).Shapes ("name of the shape").Visible=False
Next i

I tried For i = 6 To ActivePresentation.Slides.Count, and the button did not
work.

Regards!
 
G

Gato_de_Botas

Thanks, Steve!

I want to make just one shape invisible in about 15 slides.
What do you think of the expression sugested by David:
For i = 1 To ActivePresentation.Slides.Count
ActivePresentation.Slides(i).Shapes ("name of the shape").Visible=False
Next i

This expression did not work. The shape to be invisible is in the slides 6
until 20. I could solve the problem using a second sugestion of David:
For i = 6 To 20
ActivePresentation.Slides(i).Shapes ("name of the shape").Visible=False
Next i

but I would like to make the first expression to work, because it can be
very useful if I have to insert new slides in the presentation. I would like
to find what is causing the error.
 
G

Gato_de_Botas

thank you, Shyam!




Shyam Pillai said:
In addition to Steve's suggestion, you can also use this hide all shapes on
the slide:
ActivePresentation.Slides(1).Shapes.Range.Visible=False

or even build your own range, where numbers represent the z-orderposition of
the shapes.
'To hide the 1st and the 5th shape on the slide.
ActivePresentation.Slides(1).Shapes.Range(array(1,5)).Visible=false

Regards,
Shyam Pillai

Image Importer Wizard: http://skp.mvps.org/iiw.htm
 
D

David Marcovitz

Thank you for your kind words about my book.

Yes, of course it won't work if you try to hide a shape that doesn't
exist on a slide. That is why you need the exact slides that contain the
shape. VBA is very poor at reporting errors. Most of the time, it simply
does nothing (see the section of my book titled "No News Is Bad News").
The first expression (For i = 1 To ActivePresentation.Slides.Count)
would only work if you wanted to hide the same shape on ALL your slides.
If it is just on 6 through 20, then For i = 6 To 20 is the way to go.

--David
 
D

David Marcovitz

All the ways that I can think of to do what you want to do seem a bit
convoluted to me. I could imagine looping through every shape of every
slide and seeing if it matches the name and hiding it if it does. Then,
it wouldn't matter if the slides are 6 through 20 or 1 to 119 or 5, 7,
9, 22, and 26-30. It would look something like this:

For Each oSld in ActivePresentation.Slides
For Each oShp in oSld.Shapes
If oShp.Name = "name of the shape" Then
oShp.Visible = False
End If
Next oShp
Next oSld

I haven't tested this, but something like this should work, and it
doesn't look as convoluted as I thought it would. However, it is makes
the computer do a lot of busy work (but I guess the computer doesn't
really mind).

--David
 

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