Solved

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

Posted on 2014-01-22
4
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 27

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 27

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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