Solved

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

Posted on 2014-01-22
4
281 Views
Last Modified: 2014-01-23
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
Comment
Question by:WaterStreet
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:MacroShadow
ID: 39801157
Same as previous, just change:
.Highlight = True

Open in new window

to
.Highlight = False

Open in new window

0
 
LVL 18

Author Comment

by:WaterStreet
ID: 39801606
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
 
LVL 26

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39802229
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
 
LVL 18

Author Closing Comment

by:WaterStreet
ID: 39802483
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Outlook Free & Paid Tools
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now