![]() |
#1
|
|||
|
|||
![]() Looking for some assistance with code that will allow selected pages of the document the attached code is part of to be printed. (code is courtesy of Allen Wyatt and his word.tip.net postings) Sometimes it may be only page 85-86, other times it may be pages 3-4, 11-16, 61-80. It would also be good that if a custom range isn't entered that the entire document is printed. Code:
Sub PrintNumberedCopies() Dim varItem As Variable Dim bExists As Boolean Dim lCopiesToPrint As Long Dim lCounter As Long Dim lCopyNumFrom As Long ' ensure our doc variable exists bExists = False For Each varItem In ActiveDocument.Variables If varItem.Name = "CopyNum" Then bExists = True Exit For End If Next varItem ' initialize document variable if doesn't exist If Not bExists Then ActiveDocument.Variables.Add _ Name:="CopyNum", Value:=0 End If ' ask how many to print On Error GoTo Canceled lCopiesToPrint = InputBox( _ Prompt:="How many copies do you require?", _ Title:="Print and Number Copies", _ Default:="1") ' ask where to start numbering On Error GoTo Canceled lCopyNumFrom = CLng(InputBox( _ Prompt:="Number at which to start numbering copies?", _ Title:="Print and Number Copies", _ Default:=CStr(ActiveDocument.Variables("CopyNum") + 1))) ' loop through the print-write-print cycle For lCounter = 0 To lCopiesToPrint - 1 ' update the document variable ActiveDocument.Variables("CopyNum") = _ lCopyNumFrom + lCounter With Options .UpdateFieldsAtPrint = True .UpdateLinksAtPrint = True End With ActiveDocument.Fields.Update ' print this numbered copy ActiveDocument.PrintOut Copies:=1 Next lCounter Canceled: End Sub |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I print a range of pages? | thelighthouse | Word | 3 | 03-22-2018 09:50 AM |
Fail-safe way to print right page range? | New Daddy | Word | 5 | 09-22-2013 11:10 PM |
![]() |
stickyit | Outlook | 1 | 10-06-2011 09:51 AM |
![]() |
tswiers | Excel Programming | 2 | 08-11-2011 02:40 AM |
![]() |
A2Irish | Excel | 1 | 05-05-2011 05:25 PM |