Hi all,
I am using the code below to covert several pages within a worksheet to PDF format. I've been accomplishing this by printing each page to an Adobe printer then using Distiller to convert to PDF. Everything works fine but I've run into a wall trying to add cell values to the PDF file names. I need to enumerate through a range and pull the value off of each cell and add it to corresponding PDF file. I have been trying to do this using nested loops but am running into endless looping problems.
Thanks.
I am using the code below to covert several pages within a worksheet to PDF format. I've been accomplishing this by printing each page to an Adobe printer then using Distiller to convert to PDF. Everything works fine but I've run into a wall trying to add cell values to the PDF file names. I need to enumerate through a range and pull the value off of each cell and add it to corresponding PDF file. I have been trying to do this using nested loops but am running into endless looping problems.
Thanks.
Code:
Sub ExtracttoPDF()
Dim iVBreaks As Integer
Dim iTotPages As Integer
Dim pb As VPageBreak
Dim myLoop As Integer
Dim STDprinter As String
Dim PSFileName As String
Dim PDFFileName As String
Dim myPDF As PdfDistiller
Set myPDF = New PdfDistiller
PSFileName = "c:\PDF_Temp\myPostScript.ps"
STDprinter = Application.ActivePrinter
Application.ActivePrinter = "Adobe PDF on Ne05:"
Application.ScreenUpdating = False
iVBreaks = ActiveSheet.VPageBreaks.Count + 1
i = iVBreaks
For j = 1 To i
PDFFileName = "c:\PDF_Temp\PDF\" & j & ".pdf"
ActiveWindow.SelectedSheets.PrintOut From:=j, To:=j, Copies:=1, Collate:=True, PrintToFile:=True, PrToFileName:=PSFileName
myPDF.FileToPDF PSFileName, PDFFileName, ""
Kill Left(PDFFileName, Len(PDFFileName) - 3) & "log"
Kill (PSFileName)
Next
Application.ActivePrinter = STDprinter
End Sub