使用重置按钮将幻灯片设置为旧状态

时间:2016-10-28 14:15:25

标签: vba powerpoint powerpoint-vba

问题:如何在VBA中存储PowerPoint幻灯片,以便在点击重置按钮时幻灯片将恢复到原始状态?

我尝试过:

Public default_state As Slide

Sub abc()
default_state = ActivePresentation.Slides(1)
...
wonderful code
...
End Sub

Sub xyz()
ActivePresentation.Slides(1) = default_state
End Sub

此处按下重置按钮时会运行xyz sub。我很快就知道所包含的作业不受支持。

1 个答案:

答案 0 :(得分:0)

对于初学者来说是这样的:

Sub MakeDefaultSlide()

    Dim oDefaultSlide As Slide

    ' Dupe the slide
    Set oDefaultSlide = ActivePresentation.Slides(1).Duplicate(1)

    ' Tag the presentation with the slide's index so we can find it later
    ' then hide the slide
    With oDefaultSlide
        ActivePresentation.Tags.Add "DefaultSlideIndex", CStr(oDefaultSlide.SlideIndex)
        .SlideShowTransition.Hidden = True
    End With
    ' Note that you could also tag the presentation with the original slide's
    ' SlideIndex in case you're not working with slide 1

End Sub

Sub RestoreDefaultSlide()

    With ActivePresentation
        'Delete the modified slide
        .Slides(1).Delete

        ' And move the default slide back into its place
        With .Slides(CLng(.Tags("DefaultSlideIndex")) - 1)
            .MoveTo (1)
            .SlideShowTransition.Hidden = False
        End With

    End With

End Sub