PDA

View Full Version : Search a Slide for a Shape with Particular Text



nsalyani
06-02-2011, 11:14 AM
Hi there,

I basically have 2 slides on my powerpoint show. Each slide has four shapes with different text in it (A B C D E F G H). I want to search for the letter B on the first (ACTIVE) Slide and change it's shape color to ORANGE. Then move onto the same slide (NEW ACTIVE SLIDE), run the same code and search letter G on the Slide and do the same thing.

I have the following code working. However, this code searches the entire presentation for B or G and colors both the shapes to orange. I tried using WIth Statements in order to search an ACTIVE SLIDE but it din't work for some reason. COuld someone help out please!

For Each ss In ActivePresentation.Slides
For Each shp2 In ss.Shapes
If shp2.HasTextFrame Then
If StrComp(shp2.TextFrame.TextRange, "B" Or "G", vbTextCompare) = 0 Then
shp2.Fill.ForeColor.RGB = RGB(255, 165, 0)

End If
End If
Next shp2
Next ss

Cosmo
06-03-2011, 06:52 AM
Your first line will run through all slidesFor Each ss In ActivePresentation.Slides

If you only want to work with the active slide, use something like this

With ActivePresentation.Slides(ActivePresentation.SlideShowWindow.View.CurrentSh owPosition)
For Each shp2 In .Shapes
If shp2.HasTextFrame Then
If StrComp(shp2.TextFrame.TextRange, "B" Or "G", vbTextCompare) = 0 Then
shp2.Fill.ForeColor.RGB = RGB(255, 165, 0)

End If
End If
Next shp2
end with

nsalyani
06-03-2011, 09:29 AM
You are right by saying that if I use "For Each ss in Active Presentation.Slides" I will be searching every slide in the Presentation.

However, your solution did not work for me either. It makes sense logically, but unfortunately doesn't work.

Could it be because of the PPT 2010 version that I am using?

Cosmo
06-03-2011, 10:20 AM
You are right by saying that if I use "For Each ss in Active Presentation.Slides" I will be searching every slide in the Presentation.

However, your solution did not work for me either. It makes sense logically, but unfortunately doesn't work.

Could it be because of the PPT 2010 version that I am using?
Are you running this macro in Slide Show mode? If not, then you need to change the first line.

I believe your comparison line was wrong, change it to this:
If (StrComp(shp2.TextFrame.TextRange, "B", vbTextCompare) = 0) Or (StrComp(shp2.TextFrame.TextRange, "G", vbTextCompare) = 0) Then

When I run this in slide show mode in PPT2010, it does turn the textboxes orange if they match "B" or "G".

nsalyani
06-03-2011, 10:42 AM
It works!!

Thanks Cosmo!!!