Thread: [Solved] Macro to Print Custom Range
View Single Post
 
Old 05-20-2018, 03:33 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 Print macro almost there but not quite...

I have most of the macro working as I intend it BUT I'm stuck on the third InputBox sequence insofar as I am not sure how to specify and code the page range that I require to be printed and then have that page range auto-populate the With Dialogs .page line. I have a 'default range' manually typed in at the moment for 'testing' purposes.

Question two is then how do I get the With Dialogs(wddialogfileprint) to auto cycle thru so I don't have to press OK every copy that I want printed?

Code:
Sub PrintNumberedCopiesSelectionofPages()
'
' PrintNumberedCopiesSelectionofPages Macro
' Shortcut Key Alt+S
'
Dim Msg As String, Ans As Variant
    Dim lCopiesToPrint As Long
    Dim lCounter As Long
    ' Dim lRange As Long    ' is this even correct for what I am trying to do?
 
     Ans = MsgBox(Space(20) & "Is the printer configured for 2-sided printing?" & vbCrLf & vbCrLf & _
        "If not then click No, click 'Properties', select '2-sided printing' and click 'OK'.", _
        vbMsgBoxSetForeground + vbQuestion + vbYesNo, (Space(50) & "ABCDF 1234"))
    
   Select Case Ans
    
        Case vbYes
    
        Case vbNo
        
         With Dialogs(wdDialogFilePrint)
         If .Show = 0 Then End
         
         End With
        
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
      lPageRange = CLng(InputBox( _
         Prompt:="What pages require printing?", _
         Title:=(Space(45) & "ABCDF 1234"), _
         Default:="1-4"))                     ' how do I specify the page range I want to print here and have it populate the With Dialogs .pages in the print-write-print cycle line below?
        
 
    ' 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
         With Dialogs(wdDialogFilePrint)
         .Pages = "2-3"
         .Range = wdPrintRangeOfPages
         .Show
         End With
    Next lCounter       'this repeats the cycle as expected but how do I get the wddialogfileprint to auto cycle thru as well so I don't have to OK everything?  Comment out the "ask what pages need printing" code to see what I mean about auto-cycling thru
 
Canceled:
 
End Sub
Appreciate ANY help in getting this annoying last bit resolved.

cheers
Mike
Reply With Quote