Friday, May 11, 2012

How to Save PowerPoint Presentation as PDF using VBA

How to Convert PowerPoint Presentation PPT to PDF using VBA

PDF is always the universal format for sending the files. With lot of versions of MS Office and other Office suites around .. it is better to circulate the Deck as a PDF

The following snippet converts the Presentation to a PDF and saves in the same folder of the PPT

ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & ActivePresentation.Name & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint


5 comments:

  1. The details in blog are very useful and thanks for the same.
    Can you increase the width of the blog. Some images are getting cut at the ends, and we will also have less scrolling

    ReplyDelete
  2. Good Post, I was confuse in this case actually i was make A+ powerpoint presentation but i was confusing in file converting case to PDF. Thank you

    Regard
    Harry lee

    ReplyDelete
  3. rasiya10:49 PM

    You can save/convert ppt or pptx files to pdf format using VB.NET with Aspose.Slides for .NET Library. You can view the code to convert ppt or pptx files here.

    ReplyDelete
  4. Hi,

    I had a similar idea and cannot find why I have errors. The idea was to create a macro opening all my .pptx within a specified folder and create two kinds of pdfs from these.
    Note: these pdf are password protected.

    However I am now blocked as it works fine for the 1st powerpoint and then it crashes for the second telling me that the Exportasfixedformat does not work.
    Would you have any tips for me, please?

    Public wbPPT As Presentation
    Public fPPT As String
    Public fInput As String
    Public fpath As String


    Sub BatchBuilding_pdf_from_PPT()

    Dim nfichier As String, nfichier2 As String, intpos As Byte


    fInput = InputBox("Please enter the local address where are stored your PPT files (e.g. C:\... ) ")
    If fInput = "" Then
    MsgBox ("No path entered, the Importing process is cancelled")
    Exit Sub
    Else
    If Right(fInput, 1) <> "\" Then
    fInput = fInput & "\"
    Else
    fInput = fInput
    End If

    fpath = fInput

    fPPT = Dir(fpath & "*.pptx")

    Do While Len(fPPT) > 0

    nfichier = fPPT
    'find where is the extension in the name
    intpos = InStrRev(nfichier, ".")
    'replace the pptx by pdf
    nfichier = Left(nfichier, intpos - 1)
    nfichier2 = nfichier & ".pdf"

    With ProtectedViewWindows.Open(fpath & fPPT, "password").Edit("password")
    .ExportAsFixedFormat Path:=fpath & "Without notes\" & nfichier2, FixedFormatType:=ppFixedFormatTypePDF, Intent:=ppFixedFormatIntentPrint, FrameSlides:=msoTrue, PrintHiddenSlides:=msoTrue, OutputType:=ppPrintOutputSlides
    .ExportAsFixedFormat Path:=fpath & "With notes\" & nfichier2, FixedFormatType:=ppFixedFormatTypePDF, Intent:=ppFixedFormatIntentPrint, FrameSlides:=msoTrue, PrintHiddenSlides:=msoTrue, OutputType:=ppPrintOutputNotesPages
    .Close
    End With

    fPPT = Dir

    'same code as before to prepare for the next file (just in case)
    nfichier = fPPT
    'find where is the extension in the name
    intpos = InStrRev(nfichier, ".")
    'replace the pptx by pdf
    nfichier = Left(nfichier, intpos - 1)
    nfichier2 = nfichier & ".pdf"

    Loop

    MsgBox ("All presentations have been PDFied")
    End If

    End Sub

    Thanks in advance.

    ReplyDelete
  5. Anonymous9:08 PM

    This is a great snippet. I have been trying to format it to create a pdf of just one page. Has anyone cracked that code. Thanks.

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.