PowerPoint 2016 VBA - selecting a shape problem

My presentation has 10 slides. The shape "Note 85" is on Slide 2. The following code I thought would look for the shape on any of the slides. Strangely, it seems to only look at the shapes in Slide 1. But I can't see why!!!
Can somebody see what I'm missing please?
Thanks.

Note: if "Note 85" is on Slide 1 it finds it.

strShapeToSelect = "Note 85"

For Each sld In ActivePresentation.Slides

    Set shp = sld.Shapes(strShapeToSelect)

    If Not IsEmpty(shp) Then
        shp.Fill.ForeColor.RGB = RGB(255, 0, 0)
                                    
        Exit For
    End If
Next

Open in new window

hindersalivaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John WilsonCEO PowerPoint AlchemyCommented:
You are jumping out of the loop with Exit For as soon as a shape is found so it never goes beyond the first hit.

In any case you can just say:

Dim strShapeToSelect As String
Dim sld As Slide
strShapeToSelect = "Note 85"
On Error Resume Next
For Each sld In ActivePresentation.Slides
      sld.Shapes(strShapeToSelect).Fill.ForeColor.RGB = RGB(255, 0, 0)
Next

Open in new window


This will run faster

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hindersalivaAuthor Commented:
JRSW, it works! Thanks!

But sorry, in my question I foolishly took out a few lines of code to simplify and confused the issue :(
Yes there is an 'On Error Resume Next' in my code. So I'm still not sure why mine only looked at Slide 1.
The full code is

strShapeToSelect = "Note 85"

For Each sld In ActivePresentation.Slides
     On Error Resume Next
     Set shp = sld.Shapes(strShapeToSelect)
     On Error GoTo 0
     If Not IsEmpty(shp) Then
        shp.Fill.ForeColor.RGB = RGB(255, 0, 0)                           
        Exit For
     End If
Next

Open in new window


Just curious. Not essential to my project.
hindersalivaAuthor Commented:
Oh yes. It's jumping out before looking at the next slide. (like you said JRSW!)
Thanks. I'll close this question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.