Consulting

Results 1 to 11 of 11

Thread: save PPT to PDF

  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    12
    Location

    Smile save PPT to PDF

    hi,

    I am very new to PPT macros. I want to save a ppt with 20 slides as PDF but only two slides of my choice.

    upon on searching Internet I found below code.
    Plese some one modify this to suit my need.



    sub check ()

    On Error GoTo Errorhandler

    Dim slidenum As Integer

    slidenum = InputBox(Prompt:="Enter the Slide number to convert to PDF.", Default:=1



    ActivePresentation.slides(slidenum).Select

    ActivePresentation.ExportAsFixedFormatActive Presentation.Path & "\" & ActivePresentation.name& ".pdf",ppFixedFormatTypePDF, ppFixedFormatIntentPrint, , , , ,, ppPrintCurrent



    Errorhandler:

    Exit Sub



    End Sub



    Advance Thanks,
    Suresh

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    This should get you started. You might want to add some error checks

    Sub PDFMe()
    Dim lngFirst As Long
    Dim lngSecond As Long
    Dim strPath As String
    Dim ipos As Integer
    If ActivePresentation.Path = "" Then
    MsgBox "Save me first"
    Exit Sub
    End If
    ipos = InStrRev(ActivePresentation.FullName, ".")
    strPath = Left(ActivePresentation.FullName, ipos - 1) & ".pdf"
    lngFirst = InputBox("First slide number")
    lngSecond = InputBox("Second slide number")
    ActivePresentation.Slides.Range(Array(lngFirst, lngSecond)).Select
    ActivePresentation.ExportAsFixedFormat Path:=strPath, FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Dec 2011
    Posts
    12
    Location

    Smile

    Thanks for replying.
    I have tested this but I am getting
    Run time error '-2147467259 (80004005)'
    Presenation (Unknown memeber): the slides you have selected to print no longer exist. Please make another selection.


    at "ActivePresentation.ExportAsFixedFormat Path:=strPath, FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection" line.

    but My ppt has 4 slides and my selection was 1 and 2 slides.
    Please help me.

    Thanks,
    Suresh

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Looks like you must activate the slides thumbnail pane. Make sure you are in Normal view and try this


    Sub PDFMe()
    Dim lngFirst As Long
    Dim lngSecond As Long
    Dim strPath As String
    Dim ipos As Integer
    If ActivePresentation.Path = "" Then
    MsgBox "Save me first"
    Exit Sub
    End If
    ipos = InStrRev(ActivePresentation.FullName, ".")
    strPath = Left(ActivePresentation.FullName, ipos - 1) & ".pdf"
    lngFirst = InputBox("First slide number")
    lngSecond = InputBox("Second slide number")
    ActiveWindow.Panes(1).Activate
    ActivePresentation.Slides.Range(Array(lngFirst, lngSecond)).Select
    ActivePresentation.ExportAsFixedFormat Path:=strPath, FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Regular
    Joined
    Dec 2011
    Posts
    12
    Location

    Smile Thanks

    Hi,

    Thanks you John. It is working fine.

    Thanks once again

    Suresh

  6. #6
    VBAX Newbie
    Joined
    Feb 2015
    Posts
    1
    Location
    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.

  7. #7
    VBAX Newbie
    Joined
    Oct 2015
    Posts
    2
    Location
    I, too, have been running across this problem. However, I am attempting to loop through each slide and save it as an individual PDF. To my code, I added the ActiveWindow.Panes(i).Activate line of code as suggested above. The first time around worked. The second time around, I received the same: Run time error '-2147467259 (80004005)'
    Presenation (Unknown memeber): the slides you have selected to print no longer exist. Please make another selection.

    To further complicate things, when testing the loop just to activate the panes (I commented out the PDF process), it runs fine until I reach 4. (There are 153 slides to PDF individually) When I get to 4, I receive this error: Run time error -2147188160 (80048240) Panes (unknown member): Integer out of range, 4 is not in the valid range of 1 to 3.

    I have Googled about everything I can think of and cannot come up with any helpful solutions. Please let me know if you have found any work-arounds for this.

  8. #8
    VBAX Newbie
    Joined
    Jan 2016
    Posts
    1
    Location
    Quote Originally Posted by rbmerlot View Post
    I, too, have been running across this problem. However, I am attempting to loop through each slide and save it as an individual PDF. To my code, I added the ActiveWindow.Panes(i).Activate line of code as suggested above. The first time around worked. The second time around, I received the same: Run time error '-2147467259 (80004005)'
    Presenation (Unknown memeber): the slides you have selected to print no longer exist. Please make another selection.

    To further complicate things, when testing the loop just to activate the panes (I commented out the PDF process), it runs fine until I reach 4. (There are 153 slides to PDF individually) When I get to 4, I receive this error: Run time error -2147188160 (80048240) Panes (unknown member): Integer out of range, 4 is not in the valid range of 1 to 3.

    I have Googled about everything I can think of and cannot come up with any helpful solutions. Please let me know if you have found any work-arounds for this.
    I get that first error too. Searched all over Google but couldn't find a solution. Were you able to find a solution rbmerlot?

  9. #9
    VBAX Newbie
    Joined
    Oct 2015
    Posts
    2
    Location
    Technically, not a solution to the run time error, but I did completely change the way I went about it and found success. In my scenario, each of the slides that I needed has a unique title. I ended up building 2 steps in my program. The first is a loop that saved each slide as its own pptx file with the title as the file name to a specific directory. The second is a program to PDF every pptx file that is in that directory.

  10. #10
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    .Panes(1) not .Panes(i)
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  11. #11
    VBAX Newbie
    Joined
    Feb 2016
    Posts
    1
    Location

    Pls help

    Hi,

    I need to create a macro to convert selected ppts slides to pdf. The process is,

    1) i mark the slides using the markup feature
    2) run the vba code
    3) it asks me for a name to save
    4) and saves only the marks slides with the annotations on the slides

    I have gone through the code on this page, i was able to take the slide numbers as input and then save, but I need a macro which directly saves the marked slides from the active presentation. Please help.

    The macro so far,

    Sub PDFMe()
    Dim myArray() As Integer
    Dim lngSecond As Integer
    Dim strPath As String
    Dim ipos As Integer
    Dim SlidesCount As Integer
    Dim i As Integer


    If ActivePresentation.Path = "" Then
    MsgBox "Save me first"
    Exit Sub
    End If


    ipos = InStrRev(ActivePresentation.FullName, ".")
    strPath = Left(ActivePresentation.FullName, ipos - 1) & ".pdf"




    SlidesCount = InputBox("Enter the number of slides you want to export")
    For i = 1 To SlidesCount
    ReDim Preserve myArray(i)
    myArray(i) = InputBox("Enter the slide number, press ok to enter another")
    Next i


    ActiveWindow.Panes(1).Activate
    ActivePresentation.Slides.Range(myArray).Select
    ActivePresentation.ExportAsFixedFormat Path:=strPath, FixedFormatType:=ppFixedFormatTypePDF, RangeType:=ppPrintSelection
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •