PDA

View Full Version : Print Macro to Print Entire Document Accept the last page



damonj
08-07-2016, 07:19 PM
Hi Everyone, looking for some assistance with a Word Print Macro.

We have a specific requirement to print all the pages except the last page of a document to one tray and the last page to another tray.

I have successfully worked in some code to handle printing the last page of a document, however I'm unsure how to specify everything in a document but not the last page. Can anyone help? My current macro is printing all the pages including the last, then printing the last again to a different tray. This isn't ideal as you end up with the last page printed twice.

Here is what I have so far:

Dim strTempPrinterName As String
strTempPrinterName = "\\myserver\myprinterqueue"
strTempPrinterName = GetPrinter(strTempPrinterName)

With Dialogs(wdDialogFilePrintSetup)
.printer = strTempPrinterName
.DoNotSetAsSysDefault = True
.Execute
End With

With ActiveDocument.PageSetup
.FirstPageTray = 260
.OtherPagesTray = 260
End With

'Print Entire Document to Plain Buff Paper
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0


With ActiveDocument.PageSetup
.FirstPageTray = 261
.OtherPagesTray = 261
End With

'Print Last Page to Printed Buff Paper
Selection.EndKey unit:=wdStory
Application.PrintOut FileName:="", _
Range:=wdPrintCurrentPage

With ActiveDocument.PageSetup
.FirstPageTray = 262
.OtherPagesTray = 262
End With



Thanks Damon

gmayor
08-07-2016, 08:51 PM
Replace the Print all section with

Dim oRng As Range
Dim i As Long
Set oRng = ActiveDocument.Range
oRng.Collapse 0
i = oRng.Information(wdActiveEndPageNumber) - 1
Application.PrintOut FileName:="", _
Range:=wdPrintRangeOfPages, _
Item:=wdPrintDocumentWithMarkup, _
copies:=1, _
Pages:="1-" & i, _
PageType:=wdPrintAllPages, _
collate:=True, _
Background:=False, _
PrintToFile:=False, _
PrintZoomColumn:=0, _
PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0

damonj
08-07-2016, 10:06 PM
Thanks Graham,

Can confirm that this has worked!

Brilliant.

Cheers
Damon