none
Unwanted print job created RRS feed

  • Question

  • For some reason when I run the macro below, a print job is also generated that contains ALL the pages of the document. I would like to prevent that from happening.

    BACKGROUND. I have a VBA macro to print exams after a mail merge. In this example the document has 5 sections. This macro breaks the merged doc into individual print jobs for the printer so each can be individually stapled. The macro works fine. EXCEPT it also generates an unwanted job that contains all the pages of the document. Any help to explain why that happens (and prevent it) will be appreciated. Because I am printing 60 eight-page docs, the time it takes to generate the unwanted 480 page doc is aggravating.

    SYSTEM: Win7-64, Word2010-32

    My work around has been to pause the print queue until all the jobs have been created, then nuke the one with all the pages.

    Thanks in advance.
    --Lloyd

    Sub aa_exam_print()
    Dim i As Long
    With ActiveDocument
    For i = 1 To .Sections.Count Step 5
    .PrintOut Range:=wdPrintFromTo, From:="s" & i, To:="s" & i + 4
    Next i
    End With

    End Sub

    Monday, December 16, 2013 1:57 PM

Answers

  • Check the document and see if there îs exactly one section / exam with the expected number of pages? Sometimes there's a section break after the last section that doesn't "match" the expected pattern and can lead to odd results.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, December 16, 2013 4:07 PM
    Moderator
  • Thanks for the reply. I think that may be the case--extra sections at the end of the merged document.

    Do you think this will solve the problem? Make sure I never try to print past the last exam...

    Thanks in advance. --Lloyd

    Sub aa_exam_print()
    Dim i As Long
    With ActiveDocument

    Sections_per_Exam = 5

    Total_Sections = .Sections.Count

    Max_Sections = INT(Total_Sections/Sections_per_Exam) * Sections_per_Exam

    For i = 1 To Max_Sections Step Sections_per_Exam
    .PrintOut Range:=wdPrintFromTo, From:="s" & i, To:="s" & i + (Sections_per_Exam -1)
    Next i

    End With

    End Sub

    • Marked as answer by labumm Friday, April 18, 2014 2:43 PM
    Tuesday, December 17, 2013 2:16 PM

All replies

  • Check the document and see if there îs exactly one section / exam with the expected number of pages? Sometimes there's a section break after the last section that doesn't "match" the expected pattern and can lead to odd results.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, December 16, 2013 4:07 PM
    Moderator
  • Thanks for the reply. I think that may be the case--extra sections at the end of the merged document.

    Do you think this will solve the problem? Make sure I never try to print past the last exam...

    Thanks in advance. --Lloyd

    Sub aa_exam_print()
    Dim i As Long
    With ActiveDocument

    Sections_per_Exam = 5

    Total_Sections = .Sections.Count

    Max_Sections = INT(Total_Sections/Sections_per_Exam) * Sections_per_Exam

    For i = 1 To Max_Sections Step Sections_per_Exam
    .PrintOut Range:=wdPrintFromTo, From:="s" & i, To:="s" & i + (Sections_per_Exam -1)
    Next i

    End With

    End Sub

    • Marked as answer by labumm Friday, April 18, 2014 2:43 PM
    Tuesday, December 17, 2013 2:16 PM
  • I'm afraid I don't have enough information to be able to answer whether your proposed code will work, or not. You'll just have to test...

    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, December 17, 2013 3:08 PM
    Moderator
  • That works. I print 60 8-page documents. I no longer get the additional, unwanted 480 page job.
    Friday, April 18, 2014 2:45 PM