Thread: [Solved] Macro to Print Custom Range
View Single Post
 
Old 05-22-2018, 01:38 AM
kiwimtnbkr kiwimtnbkr is offline Windows 10 Office 2010 64bit
Advanced Beginner
 
Join Date: Oct 2017
Posts: 69
kiwimtnbkr is on a distinguished road
Default

Well the answer ended up being surprisingly easy. Changes to the code are highlighted in red.

Code:
Sub PrintNumberedCopiesSelectionofPages()
'
' PrintNumberedCopiesSelectionofPages Macro
' Shortcut Key Alt+S
'
Dim Msg As String, Ans As Long
    Dim lCopiesToPrint As Long
    Dim lCounter As Long
    Dim strPages As String
     
      Ans = MsgBox(Space(1) & "Is the document print settings configured  for 'Print on Both Sides?" & vbCrLf & vbCrLf & _
         "If not then click 'No', click the 'File' tab, 'Print', select 'Print on  Both Sides / Flip pages on long edge' and then press 'Alt+S'.", _
        vbMsgBoxSetForeground + vbQuestion + vbYesNoCancel, (Space(50) & "ABCDF 1234"))
   
       Select Case Ans
             
        Case vbYes
        Case vbNo
        End
        Case vbCancel
        End
        
End Select

    ' ask how many to print
    On Error GoTo Canceled
    lCopiesToPrint = InputBox( _
        Prompt:="How many copies do you require?", _
        Title:=(Space(45) & "ABCDF 1234"), _
        Default:="1")
 
    ' ask where to start numbering
    On Error GoTo Canceled
    lCopyNumFrom = CLng(InputBox( _
        Prompt:="Number at which to start numbering copies?", _
        Title:=(Space(45) & "ABCDF 1234"), _
        Default:=CStr(ActiveDocument.Variables("CopyNum") + 1)))
        
    ' ask what pages need printing
      On Error GoTo Canceled
      strPages = InputBox( _
         Prompt:="What pages require printing?", _
         Title:=(Space(45) & "ABCDF 1234"), _
         Default:="1-4")        

    ' 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 = False
                    .UpdateLinksAtPrint = True
                End With
                    ActiveDocument.Fields.Update
        ' print this numbered copy
         ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPages
         
    Next lCounter
 
Canceled:
 
End Sub
Reply With Quote