• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Extract and print only paragraphs having NO highlighted words (Word 2013 docs)

Please refer to my previous question for details at:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Q_28344319.html

In this question, I want to extract to a new document only those paragraphs that have no highlighted words in them.
0
WaterStreet
Asked:
WaterStreet
  • 2
  • 2
1 Solution
 
MacroShadowCommented:
Same as previous, just change:
.Highlight = True

Open in new window

to
.Highlight = False

Open in new window

0
 
WaterStreetAuthor Commented:
I tried that before I opened this question.  It took a long time and seemed to print most, if not all, of the paragraphs with and without highlighted words within.  I other words, that change seems to simply reprint the entire original doc.

Did it work for you on a test doc. with a couple paragraphs highlighted?
0
 
MacroShadowCommented:
Sorry my bad, try this:
Sub CopyParagraphs()
    Dim DocA As Document
    Dim DocB As Document
    Dim para As Paragraph

    Set DocA = ActiveDocument
    Set DocB = Documents.Add

    For Each para In DocA.Paragraphs
        With para.range.Find
            .Highlight = True
            If .Execute() = False Then
                para.range.Copy
                DocB.Bookmarks("\EndOfDoc").range.Text = "Page " & para.range.Characters.First.Information(wdActiveEndPageNumber) & vbCr
                DocB.Bookmarks("\EndOfDoc").range.Paste
                DocB.Bookmarks("\EndOfDoc").range.Text = vbCr & vbCr
            End If
        End With
    Next para
End Sub

Open in new window

0
 
WaterStreetAuthor Commented:
That worked well, and thanks for teaching me the full technique.

BTW, I found that the macro was giving me too many forced CR's, so I got rid of them in two code lines, as follows:

Changed:
               DocB.Bookmarks("\EndOfDoc").range.Text = "Page " & para.range.Characters.First.Information(wdActiveEndPageNumber) & vbCr

To:
               DocB.Bookmarks("\EndOfDoc").range.Text = "Page " & para.range.Characters.First.Information(wdActiveEndPageNumber) & " - "


Deleted:
                DocB.Bookmarks("\EndOfDoc").range.Text = vbCr & vbCr

WS
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now