locked
Printing Variable Pages

    Question

  • Okay... So I am a little new to VB and Word.  Here is my dilemma:
     
    I have a word document that I would like to find a specific word ("W5WW") in then I would like to print that page along with the 5 pages that follow it.
     
    Does this make sense?
     
    The word that I am searching for does not always show up on the same page in every document.  I have included my code below.  I was hoping that there was a way to make it print a range using this idea:
     
    'PgPrt1 = PgPrt1 - 1
        'PgPrt2 = PgPrt1 + 5
       
        'Application.PrintOut FileName:="", Range:=wdPrintFromTo, Copies:= _
            1, From:="PgPrt1", To:="PgPrt2"

     
    Please let me know if there is a solution to this.  I have tried everything that I can think of.  I am sure that there are more knowledgeable people out there.
     
    Thanks in advance
     
    Heather
     
    ----------------------------------------------------
    Sub DI()
    '
    ' DraftInternals Macro
    '
    '
        Dim PgPrt1
        Dim PgPrt2
       
        '-------------------------------
        ' Print the Min/Max - works for draft only - other projects you may get to many sheets
       
        Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
            wdPrintDocumentContent, Copies:=1, Pages:="2-8", PageType:= _
            wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
            True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
            PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
        Selection.Find.ClearFormatting
        '---------------------------------
       
        ' Find the W5WW indicator for the start of the 5 & 6 records
       
        With Selection.Find
            .Text = "w5ww"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
       
        Selection.Find.Execute
        '----------------------------------
       
        ' Move back 1 page - only works for draft - most projects do not need to move back a page
        ' then print that page and do this a few more times to get all 5 & 6 Pages
       
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToPrevious     'page 1
       
        ActiveDocument.PrintOut Range:=wdPrintCurrentPage
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext         'page 2
       
        ActiveDocument.PrintOut Range:=wdPrintCurrentPage
           
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext         'page 3
       
        ActiveDocument.PrintOut Range:=wdPrintCurrentPage
       
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext         'page 4
       
        ActiveDocument.PrintOut Range:=wdPrintCurrentPage
       
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext         'page 5
       
        ActiveDocument.PrintOut Range:=wdPrintCurrentPage
       
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext         'page 6
       
        ActiveDocument.PrintOut Range:=wdPrintCurrentPage
       
        '-------------------------------------------------------------------
       
        'PgPrt1 = Val(ActiveDocument.ActiveWindow.Panes(1).Pages(1).Breaks(1).PageIndex)
        'ActiveDocument.ActiveWindow.Panes(1).Pages (1)
           
        'PgPrt1 = PgPrt1 - 1
        'PgPrt2 = PgPrt1 + 5
       
        'Application.PrintOut FileName:="", Range:=wdPrintFromTo, Copies:= _
            1, From:="PgPrt1", To:="PgPrt2"
       
        Selection.Find.ClearFormatting
    End Sub
     
    Tuesday, October 03, 2006 5:23 PM