Results 1 to 8 of 8
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro to print (2003)

    Hi All,

    I am trying to right a macro that displays an input box for the user to set the print range (15) or (15-26) Or (15-19,22) Or (15-22, 25-26) Or (15,19,22,26) Etc

    And then print the first page of each range from a tray with headed paper and the rest and blank paper. So if the numbers were 15,19,22,26 all would print header paper
    but if.... the numbers were 15-22, 25-26 then pages 15 and 25 would be on headed paper.

    Heres what I have so far:
    Sub Print2()
    Dim strPrintRange As String
    Dim strHeaderPage As String
    Dim strBlankPage As String

    'Sets the print range
    strPrintRange = InputBox("Please enter the pages you want to print... ", "Input Required", , 350, 350)

    'Identifys the header page
    If Left(strPrintRange, 2) = [0-9] Then
    strHeaderPage = Left(strPrintRange, 2)
    Else
    strHeaderPage = Left(strPrintRange, 1)
    End If


    'Prints header page on headed paper and scales the page to A4 if required
    Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
    wdPrintDocumentContent, Copies:=1, Pages:=strHeaderPage, PageType:= _
    wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
    True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
    PrintZoomPaperWidth:=11907, PrintZoomPaperHeight:=16839

    'Prints rest of print range on plain paper and scales the page to A4 if required
    Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
    wdPrintDocumentContent, Copies:=1, Pages:=strBlankPage, PageType:= _
    wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
    True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
    PrintZoomPaperWidth:=11907, PrintZoomPaperHeight:=16839

    End Sub

    I have gotten very stuck with the blank pages and header pages when the print range could be so complex

    Many thanks
    Regards
    Gerbil (AKA Kevin)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to print (2003)

    Try this. You'll have to find out what to use for FirstPageTray and for OtherPagesTray.

    Sub Print2()
    Dim strPrintRange As String
    Dim strHeaderPage As String
    Dim strBlankPage As String
    Dim arrPages() As String
    Dim i As Integer

    ' Adjust the following as needed
    With ActiveDocument.PageSetup
    .FirstPageTray = wdPrinterUpperBin
    .OtherPagesTray = wdPrinterLowerBin
    End With

    'Sets the print range
    strPrintRange = InputBox("Please enter the pages you want to print... ", "Input Required", , 350, 350)
    arrPages = Split(strPrintRange, ",")
    For i = LBound(arrPages) To UBound(arrPages)
    Application.PrintOut Range:=wdPrintRangeOfPages, Pages:=Trim(arrPages(i))
    Next i
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to print (2003)

    Thanks Hans,

    I tried the code you gave me, it almost works as I expected but not quite. The files they are printing contain several letters some one page letters and some multiple page letters. I need the first page of each letter within the document to print on headed paper (tray 2)

    so if the print range is 15-20 then page 15 is the one to print on headed paper (tray 2) and the rest on plain paper (tray 3)

    however if the range is 15-20,30-32 then page 15 and page 30 are to be on headed paper.

    also if the range is 15-20,30,35-37 then page 15 and 30 and 35 will be on headed paper.

    Code I have used is

    Sub HeaderAndBlank()
    Dim strPrintRange As String
    Dim strHeaderPage As String
    Dim strBlankPage As String
    Dim arrPages() As String
    Dim i As Integer

    ' Set the printer tray to use, adjust as required
    With ActiveDocument.PageSetup
    .FirstPageTray = 2
    .OtherPagesTray = 3
    End With

    'Sets the print range
    strPrintRange = InputBox("Please enter the pages you want to print... ", "Input Required", , 350, 350)
    'Defines how to split the print range
    arrPages = Split(strPrintRange, ",")
    For i = LBound(arrPages) To UBound(arrPages)
    'Prints the document and scales to A4 if required
    Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
    wdPrintDocumentContent, Copies:=1, Pages:=Trim(arrPages(i)), PageType:=wdPrintAllPages, _
    Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
    PrintZoomRow:=0, PrintZoomPaperWidth:=11907, PrintZoomPaperHeight:=16839
    Next i
    End Sub

    Firstpagetray only works for page 1 in the document. (I think)

    Thanks Hans
    Regards
    Gerbil (AKA Kevin)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to print (2003)

    I had expected the first page tray to be used for each print job, but it actually makes sense that it doesn't.

    Would it be feasible to insert section breaks between the letters? The first page of each section will be printed from the "first page tray". You wouldn't even need code.

  5. #5
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to print (2003)

    Yes I think that is ok, as they are supposed to insert a page break before typing the next letter. Would this still work for the very first page (page 1) if it were a new file.

    Kevin
    Regards
    Gerbil (AKA Kevin)

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to print (2003)

    Yes, it would.

  7. #7
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to print (2003)

    Hans, I'm getting in a right muddle now. how do I make this work with page-breaks

    Thanks
    Kevin
    Regards
    Gerbil (AKA Kevin)

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to print (2003)

    Use next page section breaks, not page breaks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •