Christian Steinmeyer
Christian Steinmeyer

Reputation: 954

VBA: Select all slides of defined sections

I'm playing with a progress bar (with basically zero experience with VBA whatsoever). I found the following snippet online:

Sub ProgressBar()
    On Error Resume Next
    With ActivePresentation
    .SectionProperties.SlidesCount(
        For N = 2 To .Slides.Count
        .Slides(N).Shapes("Progress_Bar").Delete
        Set s = .Slides(N).Shapes.AddShape(msoShapeRectangle, 0, .PageSetup.SlideHeight - 10, N * .PageSetup.SlideWidth / .Slides.Count, 10)
        Call s.Fill.Solid
        s.Fill.ForeColor.RGB = RGB(128, 128, 128)
        s.Line.Visible = False
        s.Name = "Progress_Bar"
        Next N:
    End With
End Sub

Note the part with For N = 2 To .Slides.Count. I'd like the progress bar not to reach from the second slide the last one but rather from the second slide to the last slide of the section I called "conclusion". How can I do that?

Thanks!

Edit: My current workaround is a hard coded number of slides that I define as a variable at the beginning of the macro and then use the variable throughout the rest of it.

Upvotes: 0

Views: 3986

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

Here are a couple of bits that should get you started:

LastSlideOf returns the slide index of the last slide in the named section passed to it:

Function LastSlideOf(sSectionName As String) As Long
    Dim x As Long

    With ActivePresentation.SectionProperties
        x = SectionIndexOf(sSectionName)
        LastSlideOf = (.FirstSlide(x) + .SlidesCount(x)) - 1
    End With

End Function

Function SectionIndexOf(sSectionName As String) As Long
    Dim x As Long
    With ActivePresentation.SectionProperties
        For x = 1 To .Count
            If .Name(x) = sSectionName Then
                SectionIndexOf = x
            End If
        Next
    End With
End Function

Upvotes: 3

Related Questions