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
- First off, click “Home” tab then click the upside-down button behind “Find”.
- Next choose “Advanced Find” to open the “Find and Replace” dialog box.
- In the box, put cursor inside the “Find what” text box and then click “More”.
- Then click “Format” button and choose “Highlight”.
- Next click “Find In” tab and choose “Main Document”.
Now you will see all highlight texts are in selection now, just as below:
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.
- First and foremost, press “Alt+ F11” to open VBA editor.
- Then click “Normal”.
- And click “Insert”.
- Next choose “Module”.
- Double click on the new module to bring out the coding space.
- 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
- Then click “Run” button.
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:
- 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)
- 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.
- 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
Leave a Reply