如何用vba设置幻灯片的切换效果?

时间:2020-01-16 编辑:多美文

在vba中,SlideShowTransition对象代表了幻灯片的切换效果。

通过SlideShowTransition对象可以设置幻灯片的切换效果、换片方式、自动换片时间、持续时间、换片声音等。

以下vba代码对当前PPT中的第二个幻灯片的切换方式进行设置:

Sub QQ1722187970()
    Dim oSP As Shape
    Dim oPresentation As PowerPoint.Presentation
    Set oPresentation = PowerPoint.ActivePresentation
    Dim oSlide As Slide
    Dim oSST As PowerPoint.SlideShowTransition
    With oPresentation
        Set oSlide = .Slides(2)
        With oSlide
            Set oSST = .SlideShowTransition
            With oSST
                '不用单击换片
                 .AdvanceOnClick = msoFalse
                 '设置自动换片
                 .AdvanceOnTime = msoTrue
                 '设置自动换片时间,以秒为单位
                 .AdvanceTime = 5
                 '设置切换的速度
                 .Speed = ppTransitionSpeedMedium
                 '设置切换的持续时间
                 .Duration = 3
                .EntryEffect = ppEffectBoxDown
            End With
        End With
    End With
End Sub

以下代码将所有幻灯片的换片方式都设置为自动间隔1秒换片:

Sub QQ1722187970()
    Dim oSP As Shape
    Dim oPresentation As PowerPoint.Presentation
    Set oPresentation = PowerPoint.ActivePresentation
    Dim oSlide As Slide
    Dim oSST As PowerPoint.SlideShowTransition
    With oPresentation
        For Each oSlide In .Slides
            With oSlide
                Set oSST = .SlideShowTransition
                With oSST
                    '不用单击换片
                     .AdvanceOnClick = msoFalse
                     '设置自动换片
                     .AdvanceOnTime = msoTrue
                     '设置自动换片时间,以秒为单位
                     .AdvanceTime = 1
                     '设置切换的速度
                     .Speed = ppTransitionSpeedMedium
                     '设置切换的持续时间
                     .Duration = 3
                    .EntryEffect = ppEffectBoxDown
                End With
            End With
        Next
        .SlideShowSettings.Run
    End With
End Sub
本文已影响
相关文章