I'm asking a question that has been asked before because the previous topic has been closed. I have the same problem as Walkecba in the old topic.
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
I am trying to use the above code for macro but when I try to run the macro it stops at the point of “select the file containing the key words.” I can not select the Word document file to continue running the macro.
https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-find-multiple-words-in-a-ms-word-document/24601fee-83f6-4eca-82c3-cdba4daa1ef7