Link to home
Start Free TrialLog in
Avatar of Pseattle1
Pseattle1

asked on

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!
Avatar of Francisco Igor
Francisco Igor
Flag of Canada image

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
Avatar of Pseattle1
Pseattle1

ASKER

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.
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

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.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the assistance.