Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vba print ppt file to pdf

425 views
Skip to first unread message

intoit

unread,
Sep 8, 2009, 9:29:01 PM9/8/09
to
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


intoit

unread,
Sep 9, 2009, 12:27:01 AM9/9/09
to
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

intoit

unread,
Sep 9, 2009, 1:31:01 AM9/9/09
to
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.

Steve Rindsberg

unread,
Sep 9, 2009, 11:19:50 AM9/9/09
to
In article <547B5051-FBD6-47EC...@microsoft.com>, Intoit wrote:
> 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.

That would be an AdobePDF driver setting, I'm pretty sure.
There's an option to have it prompt for a file name or just create a file
automatically. Check for that; I'm not certain you can control *where* the file's
produced in auto-mode, but it may automatically do what you want.


==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/

Don't Miss the PPTLive User Conference! Atlanta | Oct 11-14

intoit

unread,
Sep 10, 2009, 1:55:01 AM9/10/09
to
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 Marcovitz

unread,
Sep 10, 2009, 9:06:23 AM9/10/09
to
Doesn't "Dim myPDF As PdfDistiller" have to go with the other Dim statements
at the top of the procedure?
--David

On 9/10/09 1:55 AM, in article
D215FA74-E839-417D...@microsoft.com, "intoit"
<int...@discussions.microsoft.com> wrote:

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


Steve Rindsberg

unread,
Sep 10, 2009, 10:40:05 AM9/10/09
to
In article <C6CE720F.1FCE8%marco...@loyola.edu>, David Marcovitz wrote:
> Doesn't "Dim myPDF As PdfDistiller" have to go with the other Dim statements
> at the top of the procedure?

Nope. You can dim variables pretty much anywhere you like.
It's generally considered "good form" to put the statements at the top of the
Sub/Function, but sometimes it makes more sense (ie, for code you're going to
copy/paste into a routine) to Dim the variables before you're going to use 'em.

Steve Rindsberg

unread,
Sep 10, 2009, 10:40:06 AM9/10/09
to
Nice work ... I've done something similar but I wasn't sure whether Distiller still
supported this type of automation. Happy to see that it does.

Thanks for posting the results!

0 new messages