VBA:选择定义部分的所有幻灯片 [英] VBA: Select all slides of defined sections

查看:40
本文介绍了VBA:选择定义部分的所有幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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?

谢谢!

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

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.

推荐答案

以下几点可以帮助您入门:

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

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

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

这篇关于VBA:选择定义部分的所有幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆