Print / save all the found pages in MS Word 2013.

I have a very large MS Word 2013 document.

Example: I want to find all the pages with "Smith" in it.  I find 200 pages with Smith on it.
Result desired:  I want to print out all the 200 "found" pages with Smith without specifying each page.

Method: I find all the "Smith" pages by using the find command (binocular)
I can see the results that show: headings, pages, and results.
I click pages and see all the relevant pages.
I want to print these pages and save them in a new document.

Thank you very much for looking into this problem.  I believe that Microsoft must have a way of doing this without specifying each page to print and able to save these found pages in another document, without copying and pasting each page.  

Thanks!
Pseattle1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F IgorDeveloperCommented:
If you know the number of pages you need to print/save you can print it to a PDF document using a PDF printer, and selecting all pages you need to save, separated by comma in the print dialog. (eg: 1,3,34,55,56)

If you plan to continue editing your documents you should prefer to create a "Master" document and "subdocuments"
http://www.dummies.com/how-to/content/how-to-create-a-master-document-in-word-2013.html
http://www.officetooltips.com/word/tips/creating_subdocuments.html
0
Pseattle1Author Commented:
Unfortunately, the number of found pages is too many to identify each page.   The only way to do this is via VBA or some unknown feature of word 2013.   Thanks for trying.
0
GrahamSkanRetiredCommented:
This should print to the default printer:
Option Explicit

Sub PrintPagesWithSmith()
    Dim strPages() As String
    Dim strPageString As String
    Dim i As Integer
    Dim strText As String
    Dim rng As Range
    Dim p As Integer
    
    strText = "Smith"
    Set rng = ActiveDocument.Range

    With rng.Find
        .Text = strText
        Do While .Execute()
            p = rng.Information(wdActiveEndPageNumber)
            If i > 0 Then
                If p > strPages(i - 1) Then
                    ReDim Preserve strPages(i)
                    strPages(i) = p
                    i = i + 1
                End If
            Else
                ReDim Preserve strPages(i)
                strPages(i) = p
                i = i + 1
            End If
        Loop
    End With
    strPageString = Join(strPages, ",")
    ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPageString
End Sub

Open in new window

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Pseattle1Author Commented:
Thank you.  

I tried it on a few page test document and it worked but on my larger document:

1. I got the following error:

Run-time error '9105'
String is longer than 255 characters.

---
strPageString = Join(strPages, ",")
   ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:=strPageString

(Note: ActiveDocument etc... was highlighted.)

2. I need to be able to use a name such as "John Smithsonian" so I replaced Smith with a long name.

3.  I would like to have it saved to a file named Smith and save it in word format. Then I could print it at my leisure.  

Thanks for your help.  It's almost there.
0
GrahamSkanRetiredCommented:
It won't be because of the length of the Find text, because that is unknown in to the failing line. Instead, there seems to be a restriction on the length of the 'Pages' argument, probably because the length is stored in one eight-bit byte.  Not surprising really, since it was designed for manual entry.

We have two choices.

What I regard as the elegant one is to split the parameter into pieces of less that 255 bytes, and to issue a succession of Printout commands.

However you suggest the creation of a new document that you can print at will, so here is the code for that.
Sub ExtractPagesWithSmith()
    Dim strPages() As String
    Dim strPageString As String
    Dim i As Integer
    Dim strText As String
    Dim rng As Range
    Dim p As Integer
    Dim docA As Document
    Dim docB As Document
    Dim rngSelection As Range
    
    Set docA = ActiveDocument
    Set docB = Documents.Add
    
    strText = "Smith"
    Set rng = docA.Range

    Set rngSelection = Selection.Range 'To use the "\Page" bookmark the Selection must be changed, so save the current selection for later restoraton
    
    
    With rng.Find
        .Text = strText
        Do While .Execute()
            p = rng.Information(wdActiveEndPageNumber)
             If i > 0 Then
                If p > strPages(i - 1) Then
                    rng.Select
                    docA.Bookmarks("\Page").Range.Copy
                    docB.Bookmarks("\EndOfDoc").Range.Paste
                    ReDim Preserve strPages(i)
                    strPages(i) = p
                    i = i + 1
                End If
            Else
                rng.Select
                docA.Bookmarks("\Page").Range.Copy
                docB.Bookmarks("\EndOfDoc").Range.Paste
                ReDim Preserve strPages(i)
                strPages(i) = p
                i = i + 1
            End If
        Loop
    End With
   'strPageString = Join(strPages, ", ")
    rngSelection.Select 'restore original selection
End Sub

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pseattle1Author Commented:
Thanks for the assistance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.