如何自动隐藏PowerPoint幻灯片?

时间:2018-06-19 20:18:59

标签: vba office365 powerpoint powerpoint-vba

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

1 个答案:

答案 0 :(得分:1)

这将帮助您入门,将其另存为pptm,然后将副本另存为插件:

ChangeAnswersSlideState -更改活动幻灯片是否为答案幻灯片
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