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 IamaSherpa 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

Status
Not open for further replies.

mi2nc

Technical User
Apr 9, 2009
2
US
I found a couple other threads on this subject that are closed, so I started another one. First i am not a programmer, i am a sales person developinga tool for my company to use in quoting. I want to allow the user to create a .pdf from Excel. When I run the code, I get an compile error saying "user-defined type not defined". It refers to the line: Dim myPDF As PdfDistiller anyone have any ideas?

Here is the code:

Public Sub Distill_it()

' 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("A1:b1").PrintOut copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller on Ne01:", 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
 
a) You need to set a reference to Acrobat Distiller first
(Tools->References, browse to Acrobat Disitller, check)

b) Do all your users have the Distiller? 'Cause only then will your code work.

Cheers,
MiS

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Thanks to MakeItSo I was able to get the code to at least run end to end. Now my problem is that the .ps file has some syntax error from the output.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top