Consulting

Results 1 to 5 of 5

Thread: Search a Slide for a Shape with Particular Text

  1. #1
    VBAX Regular
    Joined
    May 2011
    Posts
    14
    Location

    Search a Slide for a Shape with Particular Text

    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

  2. #2
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    Your first line will run through all slides[vba]For Each ss In ActivePresentation.Slides
    [/vba]
    If you only want to work with the active slide, use something like this

    [vba]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[/vba]

  3. #3
    VBAX Regular
    Joined
    May 2011
    Posts
    14
    Location
    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?

  4. #4
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    Quote Originally Posted by nsalyani
    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:
    [vba]If (StrComp(shp2.TextFrame.TextRange, "B", vbTextCompare) = 0) Or (StrComp(shp2.TextFrame.TextRange, "G", vbTextCompare) = 0) Then
    [/vba]
    When I run this in slide show mode in PPT2010, it does turn the textboxes orange if they match "B" or "G".

  5. #5
    VBAX Regular
    Joined
    May 2011
    Posts
    14
    Location
    It works!!

    Thanks Cosmo!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •