Print pages

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi all,

I have an Excel worksheet that consists of several pages. I need code to
print each individual page to PDF files. I have code to print to PDF via
Adobe Distiller but cannot figure out how to extract each individual page. I
am able to count vertical page breaks using VPageBreaks.Count, but how do I
extract \ print each page? Any help would be appreciated.

Thanks.
 
Hi Martin

Sub PDFTest()
On Error Resume Next
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Dim PSFileName As String, PDFFileName As String
Dim myPDF As PdfDistiller, x As String, i As Integer
x = Left(ActiveWorkbook.FullName, Len(ActiveWorkbook.FullName) - 4)
PSFileName = x & ".ps"
Set myPDF = New PdfDistiller
For i = 1 To ExecuteExcel4Macro("Get.Document(50)")
PDFFileName = x & " (Sheet" & i & ").pdf"
ActiveSheet.PrintOut From:=i, To:=i, prtofilename:=PSFileName
myPDF.FileToPDF PSFileName, PDFFileName, ""
Kill Left(PDFFileName, Len(PDFFileName) - 3) & "log"
Kill (PSFileName)
Next i
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub


--

Regards

William

XL2003

(e-mail address removed)
 
Thank you both for your help.

William - Awsome code! How can I get the value of a cell in each page and
add to the file name?

Thanks again.

Hi Martin

Sub PDFTest()
On Error Resume Next
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Dim PSFileName As String, PDFFileName As String
Dim myPDF As PdfDistiller, x As String, i As Integer
x = Left(ActiveWorkbook.FullName, Len(ActiveWorkbook.FullName) - 4)
PSFileName = x & ".ps"
Set myPDF = New PdfDistiller
For i = 1 To ExecuteExcel4Macro("Get.Document(50)")
PDFFileName = x & " (Sheet" & i & ").pdf"
ActiveSheet.PrintOut From:=i, To:=i, prtofilename:=PSFileName
myPDF.FileToPDF PSFileName, PDFFileName, ""
Kill Left(PDFFileName, Len(PDFFileName) - 3) & "log"
Kill (PSFileName)
Next i
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub


--

Regards

William

XL2003

(e-mail address removed)
 
Hi Martin,

change
PSFileName = x & ".ps"

to
PSFileName = x & "_" & TRIM(RANGE("A1").value) & ".ps"

if you are including a date be sure to format with year first, perhaps like:
PSFileName = x & "_" & TEXT(RANGE("A1").value,"yyyy_mmdd" & ".ps"
 
David thanks. The cell value will actually change from page to page. The row
is defined under Page Setup > Print titles as $1:$8 so I need to pull the
value off of each cell in this row.

Thanks.

Hi Martin,

change
PSFileName = x & ".ps"

to
PSFileName = x & "_" & TRIM(RANGE("A1").value) & ".ps"

if you are including a date be sure to format with year first, perhaps like:
PSFileName = x & "_" & TEXT(RANGE("A1").value,"yyyy_mmdd" & ".ps"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top