How to select slides in ppt which have the same custom layout, or contain a given shape or text?

Viewed 79

Is there a way in VBA to select all the slides in active ppt doc that use a given custom layout?

CustomLayout.Name=”1_separator”   
CustomLayout.Index=”1”  

So far, I have played with this idea:

For Each CustomLayout In ActivePresentation.SlideMaster.CustomLayouts
If CustomLayout.Name = "1_Separator" Then  
ActivePresentation.Slides.Range.Select  
Exit For  
End If  
Next  
End Sub

However, it selects all the slides in the ppt (not only the ones with ”1_separator”), so it is not what I need.

My overall aim is to create an automated Table of Contents in ppt, for that I would like to choose particular slides with macro.

Alternatively, I could put a shape or specific text box on the slides, based on which I am going to create a Table of Contents.But I don’t know the code for selecting slides with a given shape or text, either.

I will be grateful for any help on this.

1 Answers
Sub SelectSlidesWithGivenCustomLayout()

    Dim slidesToSelect(999)
    Dim currentSlide As Slide
    Dim counter As Integer
    counter = 0

    For Each currentSlide In ActivePresentation.Slides
        If currentSlide.CustomLayout.Name = "1_Separator" Then
            slidesToSelect(counter) = currentSlide.SlideIndex
            counter = counter + 1
        End If
    Next

    ActivePresentation.Slides.Range(slidesToSelect).Select

End Sub
Related