Share via

How to Find multiple words in a MS Word document?

Anonymous
2020-07-26T02:36:21+00:00

I have a 748 page Word document. I need to verify that 198 Key Terms are listed in the document. Can the "Find" feature in the HOME tab be used to find and highlight multiple Key Terms in a single search?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

8 answers

Sort by: Most helpful
  1. Charles Kenyon 166.7K Reputation points Volunteer Moderator
    2020-07-28T18:31:44+00:00

    Try this:

    Sub KeyWordHighlight()

        ' Charles Kenyon - From Doug Robbins' code

        Dim DocSource As Document, DocTarget As Document

        Dim rng As Range

        Dim FD As FileDialog

        Dim strFileName As String

        Dim i As Long

        Dim rngKeyword As Range

        Dim strKeyword As String

        Set DocTarget = ActiveDocument  ' THIS IS THE LONG DOCUMENT

        Set FD = Application.FileDialog(msoFileDialogOpen) ' does not work:(msoFileDialogFolderPicker)

        With FD

            .Title = "Select the file containing the key words."

            .AllowMultiSelect = False

            If .Show = -1 Then

                strFileName = .SelectedItems(1)

            Else

                MsgBox "You did not select the file containing the key words."

                Exit Sub

            End If

        End With

        Set DocSource = Documents.Open(strFileName)

        With DocSource

            For i = 1 To .Paragraphs.Count

                '   COMMENT OUT MARKING OF TEXT IN SOURCE

                Set rngKeyword = .Paragraphs(i).Range

                rngKeyword.MoveEnd wdCharacter, -1

                strKeyword = rngKeyword.Text

    '            If InStr(DocTarget.Range, strKeyword) > 0 Then

    '                rngKeyword.Font.ColorIndex = wdGreen

    '            Else

    '                rngKeyword.Font.ColorIndex = wdRed

    '            End If

                With DocTarget.Range.Find

                    .ClearFormatting

                    .Replacement.ClearFormatting

                    .Text = strKeyword

                    .Replacement.Highlight = wdYellow

                    .Forward = True

                    .Execute Replace:=wdReplaceAll

                End With

            Next i

            .Close SaveChanges:=False

            Set DocTarget = Nothing

            Set FD = Nothing

            Set rngKeyword = Nothing

            Set rng = Nothing

        End With

    End Sub

    Instructions for Installing Macros from Forums or Websites by Graham Mayor, MVP

    Here are temporary links to my test document and list:

    10+ people found this answer helpful.
    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 322.9K Reputation points MVP Volunteer Moderator
    2020-07-26T06:02:24+00:00

    If you run a macro containing the following code when the 748 page document is the active document, it will ask you to select the file that contains the keywords, (it is assumed that each one is in a separate paragraph) and then it will open that document and if the word appears in the 748 page document, the Font Color of the word in the list of keywords will be turned to Green and if it is not found, it will be turned to Red.

    Dim DocSource As Document, DocTarget As Document

    Dim rng As Range

    Dim FD As FileDialog

    Dim strFileName As String

    Dim i As Long

    Dim rngKeyword As Range

    Dim strKeyword As String

    Set DocTarget = ActiveDocument

    Set FD = Application.FileDialog(msoFileDialogFolderPicker)

    With FD

        .Title = "Select the file containing the key words."

        .AllowMultiSelect = False

        If .Show = -1 Then

            strFileName = .SelectedItems(1)

        Else

            MsgBox "You did not select the file containing the key words."

            Exit Sub

        End If

    End With

    Set DocSource = Documents.Open(strFileName)

    With DocSource

        For i = 1 To .Paragraphs.Count

            Set rngKeyword = .Paragraphs(i).Range

            rngKeyword.MoveEnd wdCharacter, -1

            strKeyword = rngKeyword.Text

            If Instr(DocTarget.Range, strKeyword) > 0 Then

                rngKeyword.Font.ColorIndex = wdGreen

            Else

                rngKeyword.Font.ColorIndex = wdRed

            End If

        Next i

    End With

    6 people found this answer helpful.
    0 comments No comments
  3. Charles Kenyon 166.7K Reputation points Volunteer Moderator
    2020-07-27T20:21:25+00:00

    "highlight"

    Do you want, in your 748 page document, to add highlighting to those key terms?

    Do you want the same highlighting?

    Which color?

    3 people found this answer helpful.
    0 comments No comments
  4. Doug Robbins - MVP - Office Apps and Services 322.9K Reputation points MVP Volunteer Moderator
    2020-07-30T09:16:46+00:00

    If you send me a copy of the documents, referencing this thread in the covering email message, I will investigate the issue.

    2 people found this answer helpful.
    0 comments No comments
  5. Doug Robbins - MVP - Office Apps and Services 322.9K Reputation points MVP Volunteer Moderator
    2020-07-26T03:06:38+00:00

    You would need to use a macro.  Where do you have the list of key terms?

    1 person found this answer helpful.
    0 comments No comments