View Single Post
 
Old 08-11-2018, 08:38 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following macro will put all the unique highlighted words or phrases into a new document each to a new line:
Code:
Sub ExtractWords()
Dim oDoc As Document
Dim oSource As Document
Dim oRng As Range
Dim Coll As Collection
Dim i As Long
    Set oSource = ActiveDocument
    Set oRng = oSource.Range
    Set Coll = New Collection
    With oRng.Find
        .Highlight = True
        Do While .Execute
            On Error Resume Next
            Coll.Add oRng.Text, oRng.Text
            oRng.Collapse 0
        Loop
    End With
    If Coll.Count > 0 Then
        Set oDoc = Documents.Add
        For i = 1 To Coll.Count
            oDoc.Range.InsertAfter Coll(i) & vbCr
        Next i
    End If
lbl_Exit:
    Set oDoc = Nothing
    Set oSource = Nothing
    Set oRng = Nothing
    Set Coll = Nothing
    Exit Sub
End Sub
http://www.gmayor.com/installing_macro.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote