VBA: Select all slides of defined sections

妖精的绣舞 提交于 2020-07-24 03:07:49

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/43516312/vba-select-all-slides-of-defined-sections

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!