VBA:Select 定义部分的所有幻灯片

VBA: Select all slides of defined sections

我正在玩进度条(基本上 VBA 经验为零)。我在网上找到了以下片段:

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

注意 For N = 2 To .Slides.Count 的部分。我不希望进度条从第二张幻灯片到达最后一张幻灯片,而是从第二张幻灯片到达我称为 "conclusion" 部分的最后一张幻灯片。我该怎么做?

谢谢!

编辑:我目前的解决方法是对幻灯片的数量进行硬编码,我在宏的开头将其定义为变量,然后在其余部分使用该变量。

这里有一些可以帮助您入门的信息:

LastSlideOf returns 传递给它的命名部分中最后一张幻灯片的幻灯片索引:

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