PDA

View Full Version : save PPT to PDF



msuresh
06-11-2013, 02:14 AM
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

John Wilson
06-11-2013, 05:03 AM
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

msuresh
06-11-2013, 10:16 PM
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

John Wilson
06-12-2013, 03:05 AM
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

msuresh
06-12-2013, 09:17 PM
Hi,

Thanks you John. It is working fine.

Thanks once again

Suresh

bab_ass
02-19-2015, 06:02 AM
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.

rbmerlot
10-02-2015, 08:22 AM
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.

McHarvey
01-28-2016, 06:22 AM
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?

rbmerlot
01-28-2016, 07:01 AM
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.

John Wilson
01-28-2016, 07:11 AM
.Panes(1) not .Panes(i)

afroz
02-07-2016, 01:50 PM
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