vba print ppt file to pdf

I

intoit

Hi,

I'm using excel 2003 and I've got Acrobat Distiller/Professional Version 8.
Currently, I've got some vba code that creates a ppt presentation and then
saves it as a ppt file based on the name of the excel file from which a
series of charts and text are imported. The code I'm using to save the ppt
works great (see below). Now, I would like to print the ppt file into a pdf
file. I found some vba code on the net that appears relevant to my problem,
but I can't figure out how to modify it for my purposes.

Thanks for any advice.

***code I'm using to save ppt file
Dim sName As String
sName = ActiveWorkbook.Name
sName = Mid$(sName, 1, InStr(sName, ".") - 1)
sName = ActiveWorkbook.Path & "\" & sName & ".ppt"
PP.ActivePresentation.SaveAs Filename:=sName
Application.DisplayAlerts = True

***Code I found on the net to print an excel range to pdf file
Private Sub CommandButton1_Click()

' Define the postscript and .pdf file names.
Dim PSFileName as String
Dim PDFFileName as String
PSFileName = "c:\myPostScript.ps"
PDFFileName = "c:\myPDF.pdf"


' Print the Excel range to the postscript file
Dim MySheet As WorkSheet
Set MySheet = ActiveSheet
MySheet.Range("myRange").PrintOut copies:=1, preview:=False,
ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True,
prtofilename:=PSFileName


' Convert the postscript file to .pdf
Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller
myPDF.FileToPDF PSFileName, PDFFileName, ""


End Sub
 
I

intoit

I seem to have found the solution, for anyone interested:

'Save ppt. presentation as ppt.
Dim sName As String
sName = ActiveWorkbook.Name
sName = Mid$(sName, 1, InStr(sName, ".") - 1)
sName = ActiveWorkbook.Path & "\" & sName & ".ppt"
PP.ActivePresentation.SaveAs Filename:=sName
Application.DisplayAlerts = True

'Print ppt. presentation as pdf and save pdf

With PP.ActivePresentation.PrintOptions
.PrintInBackground = msoFalse
.RangeType = ppPrintAll
.Collate = msoTrue
.PrintColorType = ppPrintColor
.FitToPage = msoFalse
.FrameSlides = msoFalse
.ActivePrinter = "Adobe PDF"
End With
PP.ActivePresentation.SaveAs Filename:=sName
 
I

intoit

Actually, the code seems unstable, or is my mind playing tricks on me?
Running the code, now, prompts the user to specify where to print (i.e.,
save) the pdf file via the print dialogue box. It wasn't doing that earlier.
I'd like the code to automatically save the pdf file within the same folder
that the ppt presentation is saved.

Any ideas how to do that? Thanks.
 
I

intoit

Thanks for the tip, Steve. I found the option within Adobe, but it didn't
automatically find the directory path. Anyway, I've now got some reliable
code that saves a ppt file to a pdf, and it does so into the same directory
path as the ppt file. It's pretty simple, looking at it, now.

Sub ppt_to_pdf ()

Dim psName As String
Dim pdfName As String

psName = ActiveWorkbook.Name
psName = Mid$(psName, 1, InStr(psName, ".") - 1)
psName = ActiveWorkbook.Path & "\" & psName & ".ps"

pdfName = ActiveWorkbook.Name
pdfName = Mid$(pdfName, 1, InStr(pdfName, ".") - 1)
pdfName = ActiveWorkbook.Path & "\" & pdfName & ".pdf"

PP.ActivePresentation.PrintOut PrintToFile:=psName
Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller
myPDF.FileToPDF psName, pdfName, ""
Kill psName
PP.Quit

End sub
 
D

David Marcovitz

Doesn't "Dim myPDF As PdfDistiller" have to go with the other Dim statements
at the top of the procedure?
--David

Thanks for the tip, Steve. I found the option within Adobe, but it didn't
automatically find the directory path. Anyway, I've now got some reliable
code that saves a ppt file to a pdf, and it does so into the same directory
path as the ppt file. It's pretty simple, looking at it, now.

Sub ppt_to_pdf ()

Dim psName As String
Dim pdfName As String

psName = ActiveWorkbook.Name
psName = Mid$(psName, 1, InStr(psName, ".") - 1)
psName = ActiveWorkbook.Path & "\" & psName & ".ps"

pdfName = ActiveWorkbook.Name
pdfName = Mid$(pdfName, 1, InStr(pdfName, ".") - 1)
pdfName = ActiveWorkbook.Path & "\" & pdfName & ".pdf"

PP.ActivePresentation.PrintOut PrintToFile:=psName
Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller
myPDF.FileToPDF psName, pdfName, ""
Kill psName
PP.Quit

End sub

--
David M. Marcovitz
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
Microsoft PowerPoint MVP
Associate Professor, Loyola University Maryland
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top