Bulding pdf-files with vba and acrobat 6.0

M

Martin Beering

Hallo to all,

since hours I am trying to create pdf-files with vba and acrobat 6.0.
I would like to pass the path and filename by a variable. But it dosn't
work.
Has anyone an idea how I can do this.

Many thanks in advane and greetings from Bremen (Germany)
Martin Beering
 
D

Dan E

Martin,

I can remember having trouble's automating the PDF printing.
Though I can't remember exactly what they were. I found this
macro on somebodies site and it works well...

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
ActiveSheet.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, ""

Kill (PSFileName)

End Sub

You can have it prompt for a save as name by changing
PDFFileName = "c:\myPDF.pdf" 'to:
PDFFileName = Application.GetSaveAsFilename

Note: Works on Acrobat 5. I won't make any guarantees about 6
Watch out for word wrap on the code

Dan E
 

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