PDA

View Full Version : converting .ps to .pdf



Eddie
07-08-2008, 02:49 PM
I posted on this a while back and then got side tracked on other topics. Basically I am trying to write a script that will:

1) Take the file name and assign it to variables
2) Enter those variables in the form of a serial number is a particular cell
3) Select which cells i want printed
4) Print those cells to a .pdf
5) Clear the cell the with serial number


Here is the code that I have. It will print the .ps file, but will not convert it to a .pdf. I have selected "Do not send fonts to 'Adobe PDF'" in the printing preferences.

Any ideas?

Sub PrintSelection()
'creates strings to be set
Dim SerialDate As String
Dim SerialNum As String
Dim FullFileName As String
Dim SerialNumCell As String



'sets the FullFileName variable value to the name of the file
FullFileName = ActiveWorkbook.Name
'takes the first four numbers from the FullFileName string and assigns them to the SerialDate string
SerialDate = Mid(FullFileName, 1, 4)
'takes the next four numbers from the FullFileName string and assigns them to the SerialNum string
SerialNum = Mid(FullFileName, 5, 4)
'Selects cell H8 and then enters the serial number based off of the file name in the format "SN: ####-####"
Range("H8").Select
ActiveCell.FormulaR1C1 = "SN: " & SerialDate & "-" & SerialNum


'Selects the cells that are to be printed
Range("A1:L107").Select

'Creates new strings for the printing functions
Dim PSFileName As String
Dim PDFFileName As String
Dim LogFile As String
PSFileName = "U:\500-4614-00 HDVS\Deviations\DCR Test Results" & SerialDate & "-" & SerialNum & ".ps"
PDFFileName = "U:\500-4614-00 HDVS\Deviations\DCR Test Results" & SerialDate & "-" & SerialNum & ".pdf"
LogFile = "U:\500-4614-00 HDVS\Deviations\DCR Test Results" & SerialDate & "-" & SerialNum & ".log"

'Prints selection to PDF printer
Application.ActivePrinter = "Adobe PDF on Ne05:"
ActiveWindow.Selection.PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF on Ne05:", Collate:=True, PrToFileName:=PSFileName

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

'Deletes the .ps file
Dim KillPSFile As String
KillPSFile = PSFileName
'Check that file exists
If Len(Dir$(KillPSFile)) > 0 Then
'First remove readonly attribute, if set
SetAttr KillPSFile, vbNormal
'Then delete the file
Kill KillPSFile
End If
'Deletes the .log file
Dim KillLogFile As String
KillLogFile = LogFile
'Check that file exists
If Len(Dir$(KillLogFile)) > 0 Then
'First remove readonly attribute, if set
SetAttr KillLogFile, vbNormal
'Then delete the file
Kill KillLogFile
End If


'Clear the Serial Number Cell
Range("H8").Select
ActiveCell.FormulaR1C1 = ""
'Close the workbook
ActiveWorkbook.Close SaveChanges:=False



End Sub