none
VBA Code to export one PowerPoint slide (save as) to PDF file format RRS feed

  • General discussion

  • This code is a compilation of a few folks efforts.  It is for PowerPoint, and the code creates a printable page (certificate) that prints to default printer AND exports the one PowerPoint slide (save as) to PDF file format.

    Though it may not be elegant, it does work. Please feel free to provide better code.   The key to this function, ActivePresentation.ExportAsFixedFormat, is to be sure to include all options.  Placement of the print option is critical (in this case ppPrintCurrent). 

    =============

    Sub PrintablePage()
    'Set environment for creating a score sheet and certificate of completion form
    'for passing score
       
        Dim printableSlide As Slide
       
        Set printableSlide = ActivePresentation.Slides.Add(Index:=25, _
            Layout:=ppLayoutText)
        printableSlide.Shapes(1).TextFrame.TextRange.Text = userName
            printableSlide.Shapes(2).TextFrame.TextRange.Text = _
            "Final Score: " & numCorrect & " out of " & numCorrect + numIncorrect
           
        If numCorrect >= 16 Then
               
            Set printButton = ActivePresentation.Slides(25).Shapes.AddShape _
                (msoShapeActionButtonCustom, 550, 200, 150, 75)
            printButton.TextFrame.TextRange.Text = "Print Score Sheet"
            printButton.ActionSettings(ppMouseClick).Action = ppActionRunMacro
            printButton.ActionSettings(ppMouseClick).Run = "PrintResults"
                           
            ActivePresentation.SlideShowWindow.View.GotoSlide (25)
            ActivePresentation.Saved = True
       
        Else
            MsgBox ("Sorry - you scored " & numCorrect & " out of " & numCorrect + numIncorrect _
            & ", " & userName & ".  You may retake the quiz now or later.")
       
            ActivePresentation.SlideShowWindow.View.GotoSlide (24)
            ActivePresentation.Slides(25).Delete
                          
        End If
       
    ==========================

    Sub PrintResults()
    'Prints certificate of completion (CoC) to default printer and exports CoC to PDF file

    'Sets button options for printing and exiting
        printButton.Visible = False ' turns button off for printing

        ActivePresentation.PrintOut From:=25, To:=25
       
        ActivePresentation.ExportAsFixedFormat _
        ActivePresentation.Path & "\" & userName & ".pdf", _
        ppFixedFormatTypePDF, _
        ppFixedFormatIntentPrint, _
        msoTrue, ppPrintHandoutVerticalFirst, ppPrintOutputBuildSlides, _
        msoFalse, , ppPrintCurrent, , _
        False, True, True, True, False
                
        printButton.Visible = True ' turns button on for selection
       
        Set exitButton = ActivePresentation.Slides(25).Shapes.AddShape _
            (msoShapeActionButtonCustom, 550, 300, 150, 75)
        exitButton.TextFrame.TextRange.Text = "Exit"
        exitButton.ActionSettings(ppMouseClick).Action = ppActionRunMacro
        exitButton.ActionSettings(ppMouseClick).Run = "EndNow"
       
        MsgBox ("If you exit the quiz, your scores and certificate will be deleted.")
         
        ActivePresentation.SlideShowWindow.View.GotoSlide (25)
       
    End Sub



    • Edited by DJ Kneed Friday, November 30, 2012 1:57 PM
    Thursday, November 29, 2012 7:54 PM

All replies