Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel to PDF Using Visual Basic 1

Status
Not open for further replies.

JabbaTheNut

Programmer
Jul 29, 2002
176
US
I have used the following VB code to print an Excel range to an Adobe Acrobat .PDF file. The steps to accomplish this are as follows:

1. Print the range to a postscript file using Acrobat Distiller
2. Convert postscript file to .PDF using Acrobat Distiller API.

Make sure that you uncheck the "Do not send fonts to Distiller" option in the Distiller properties. You do this by entering the Distiller properties>>General Tab>>Printing Preferences>>Adobe PDF Settings and uncheck the "Do not send fonts to Distiller" option. You will get an error if you don't do this.

In the Excel Visual Basic Editor, make sure you include a reference to Acrobat Distiller.

Here is the code....

*********************************************
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, prttofilename:=PSFileName

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

End Sub
********************************************

And that is all there is to it! I hope this tip is helpful to some of you. Game Over, Man!
 
This is very old, but it was very helpful ;-).

I'll just add that you have to add a reference to the Acrobat Distiller in your VB project.
 
The Sub has compile problem:

...prttofilename:

Please check it out.
 
Simply replace prttofilename by PrToFileName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top