2 Handy Methods to Extract Highlighted Texts from Your Word Document

In this article, we would like to show you 2 handy methods to extract highlighted texts from your Word document.

Every so often, we are likely to highlight texts with colors when navigating through document. All these pieces of texts may scatter around the whole article but they definitely deserve our attention. Therefore, we can just export and arrange them in another document for quick review next time, saving us from scrolling mouse wheel over and over again.

Method 1: Utilize the “Advanced Find” Feature

  1. First off, click “Home” tab then click the upside-down button behind “Find”.
  2. Next choose “Advanced Find” to open the “Find and Replace” dialog box.Click "Home"->Click the Button->Click "Advanced Find"
  3. In the box, put cursor inside the “Find what” text box and then click “More”.
  4. Then click “Format” button and choose “Highlight”.Click "Format"->Choose "Highlight"
  5. Next click “Find In” tab and choose “Main Document”.Click "Find In"->Choose "Main Document"

Now you will see all highlight texts are in selection now, just as below:The Finding Results in Selection

You can copy and paste them to a new document then.

Method 2: Use Word VBA

As shown in our sample, it’s not unusual to have multiple texts in different highlighting colors. Now let’s talk about the way to get all contents in the same highlighting color first.

  1. First and foremost, press “Alt+ F11” to open VBA editor.
  2. Then click “Normal”.
  3. And click “Insert”.
  4. Next choose “Module”.Click "Normal"->Click "Insert"->Click "Module"
  5. Double click on the new module to bring out the coding space.
  6. Now paste the following codes there:
Sub ExtractHighlightedTextsInSameColor()
  Dim objDoc As Document, objDocAdd As Document
  Dim objRange As Range

  Set objDoc = ActiveDocument
  Set objDocAdd = Documents.Add
  objDoc.Activate

  With Selection
    .HomeKey Unit:=wdStory
     With Selection.Find
       .Highlight = True
       Do While .Execute
         If Selection.Range.HighlightColorIndex = wdYellow Then
           Set objRange = Selection.Range
           objDocAdd.Range.InsertAfter objRange & vbCr 
           Selection.Collapse wdCollapseEnd
         End If
       Loop
     End With
  End With
End Sub
  1. Then click “Run” button.Paste Codes->Click "Run"

You will have a new document with all highlighted texts in it.

Then there is another macro which shall enable you to collect all highlighted texts of the same color from multi-document. What you need to do is to organize them all in one folder and take the above steps, but replace the macro with this one:

Sub ExtractHighlightedTextsInSameColorFromMultiDoc()
  Dim objDoc As Document, objDocAdd As Document
  Dim strFile As String, strFolder As String
  Dim objRange As Range
 
  '  Initialization
  strFolder = "C:\Users\Public\Documents\New folder\"
  strFile = Dir(strFolder & "*.docx", vbNormal)
 
  Set objDocAdd = Documents.Add
 
  '  Precess each file in the file folder.
  While strFile <> ""
  Set objDoc = Documents.Open(FileName:=strFolder & strFile)
 
  With Selection
    .HomeKey Unit:=wdStory
    With Selection.Find
      .Highlight = True
      Do While .Execute
        If Selection.Range.HighlightColorIndex = wdYellow Then
          Set objRange = Selection.Range
          objDocAdd.Range.InsertAfter objRange & vbCr
          Selection.Collapse wdCollapseEnd
        End If
      Loop
    End With
  End With
 
  objDoc.Close
  strFile = Dir()
  Wend
End Sub

Notes:

  1. First as you can see, the 2 macros extract all texts in yellow. You can certainly replace the code “wdYellow” with other colors. Here is the link you can visit: https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2003/aa172829(v=office.11)
  2. Secondly, if you want to collect all highlighted texts in different colors, you just need to delete the “If Selection.Range.HighlightColorIndex = wdYellow Then” and “End If” lines.
  3. Thirdly, in code line “strFolder = “C:\Users\Public\Documents\New folder\” in second macro, replace the path string path with that of the folder you have. And don’t forget to add “\” at the end.

Backup is never too late

In a word, we have put so much emphasis on backup that most of you should know how important it is now. As such, we can still fail to back up on a regular basis. And the truth is, without backup, the only option left once doc corruption happens is to get a data retrieving tool.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including xlsx repair and pdf repair software products. For more information visit www.datanumen.com

4 responses to “2 Handy Methods to Extract Highlighted Texts from Your Word Document”

  1. Alas, the program does not work. If hangs almost immediately, eating up 25% of the CPU and leaves Word not responding. I tried it on .doc and .docx files, just in case.

    Windows 10; latest Office 365 Word version.

    Since I don’t know Visual Basic, I’m outta luck. Recommend to other newbies not to bother trying it, I just ate up a half hour. No worries, though, “free” software doesn’t promise anything.

  2. Ms. Chen,

    Your VBA macro to copy all highlighted text and then copy them into a new Word document is FANTASTIC!!! Is there any way to add the path for each file, sort of like this:

    Highlighted text number 1
    File path for document where Highlighted text number 1 was found
    Highlighted text number 2
    File path for document where Highlighted text number 2 was found
    Highlighted text number 3
    File path for document where Highlighted text number 3 was found
    Etc?

    Thanks in advance for any help!

Leave a Reply

Your email address will not be published. Required fields are marked *