Solved

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

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IT Desktop Support 11 75
Where to download Microsoft Form 2.0 Object Library. 2 38
Macro on Enter for text form field options. 6 35
MIN per Month 8 24
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
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…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

832 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