Solved

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

Posted on 2014-01-22
4
282 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Display multiple images in report 12 106
outlook 2013 key shortcuts 28 52
Office 2016 User Guides 5 33
Compile Error 7 41
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

895 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