View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
c1802362[_2_] c1802362[_2_] is offline
external usenet poster
 
Posts: 65
Default issues with getting .pdfs to be created

I've tried a number of ways to get my VBA code to create and save pdf
files from excel. I've used a number of different code scraps from
this group and others, and the only thing that works on my system
(Excel 2003 running on Windows XP) is the following - with caveats:

The issue is that when I launch the code, it won't run if the Adobe
setup box "Rely on system fonts only" is checked. If I uncheck the box
manually, the code works fine. The issue is that for my users to
manually go into the Print menu and change the preferences each time
they run the code the first time is impractical. Once the box has been
unchecked, there's no issue as long as the application stays open.

Interestingly, using the normal method of creating a pdf from Excel
(launching from the toolbar button in Excel) the checked box is the
default setting and everything runs fine.

So,....any suggestions?

Art

code follows:

Sub Print_PDF()

'need to check Reference to Acrobat Distiller in Tools --
References
' ensure "Rely on system fonts only..." box is unchecked on page
setup
'Define the postscript and .pdf file names.

Dim PSFileName As String
Dim PDFFileName As String
Dim lclFileName As String

lclFileName = Cells(1, 1) ' filename is contained in first
cell

PSFileName = "D:\My Documents\" & lclFileName & ".ps"
PDFFileName = "D:\My Documents\" & lclFileName & ".pdf"
'Print the Excel range to the postscript file

'was originally ActivePrinter = "Adobe PDF"

ActiveWindow.SelectedSheets.PrintOut copies:=1, preview:=False,
ActivePrinter:="Adobe PDF 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, ""

Kill "D:\My Documents\" & lclFileName & ".ps"
Kill "D:\My Documents\" & lclFileName & ".log"

End Sub