首页 > 解决方案 > 如何自动隐藏 PowerPoint 幻灯片?

问题描述

我在我的讲座中使用 PowerPoint 并为我的学生打印幻灯片的子集(以便他们在我展示我的答案之前填写空白)。目前,我在幻灯片的左下角放了一个浅蓝色圆圈,我想在打印时隐藏(但不是在讲课时)。然后,当需要打印幻灯片时,我会手动隐藏它们,然后在讲课之前取消隐藏所有幻灯片。有没有办法自动化这个过程?我在 PC 和 Mac 上都使用 Office 365。

标签: vbaoffice365powerpoint

解决方案


这将使您开始,将其保存为 pptm,然后将副本另存为插件:

ChangeAnswersSlideState- 将 activeslide 更改为答案幻灯片
PrintStudentHandout- 隐藏答案幻灯片,然后打印,然后取消隐藏

Option Explicit

Private Const ANS_ID As String = "ANS"

Sub PrintStudentHandout()
    ChangeAnswersSlideVisible
    With ActivePresentation
        .PrintOptions.ActivePrinter = "Microsoft XPS Document Writer"
        .PrintOut
    End With
    ChangeAnswersSlideVisible msoFalse
End Sub

Private Sub ChangeAnswersSlideVisible(Optional Hide As MsoTriState = msoTrue)
    Dim oSlide As Slide, oShp As Shape
    For Each oSlide In ActivePresentation.Slides
        For Each oShp In oSlide.Shapes
            If IsAnswersShape(oShp) Then
                oSlide.SlideShowTransition.Hidden = Hide
                Exit For
            End If
        Next oShp
    Next oSlide
End Sub

Sub ChangeAnswersSlideState()
    Dim oShp As Shape, bChanged As Boolean
    bChanged = False
    For Each oShp In Application.ActiveWindow.View.Slide.Shapes
        If IsAnswersShape(oShp) Then
            oShp.Delete
            bChanged = True
        End If
    Next oShp
    If Not bChanged Then MakeAnswersSlide
End Sub

Private Sub MakeAnswersSlide(Optional ByRef AnswerSlide As Slide = Nothing)
    If AnswerSlide Is Nothing Then Set AnswerSlide = Application.ActiveWindow.View.Slide
    With AnswerSlide.Shapes.AddShape(msoShapeOval, -80, 460, 72, 72)
        .TextFrame.TextRange.Text = ANS_ID
    End With
End Sub

Private Function IsAnswersShape(ByRef CheckShape As Shape) As Boolean
    Dim bIsAnAnswerShape As Boolean
    bIsAnAnswerShape = False
    With CheckShape
        If .AutoShapeType = msoShapeOval Then
            If .HasTextFrame Then
                If .TextFrame.TextRange.Text = ANS_ID Then
                    bIsAnAnswerShape = True
                End If
            End If
        End If
    End With
    IsAnswersShape = bIsAnAnswerShape
End Function

推荐阅读