Share via

How to Find and Replace Different Words into the Single Word in WORD in Office365?

Anonymous
2023-07-26T17:57:55+00:00

I have a MS Word File with 10 pages.

I write it totally in English. I want to Find and Replace different words in my file with the same word.

For example, "dog or cat or bird" into the single word "pet"

How can I do it?

Regards,

Duy Truong

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

4 answers

Sort by: Most helpful
  1. Anonymous
    2023-07-27T05:30:42+00:00

    Thank you.

    Sub ReplaceMultipleWords()

    Dim searchWords As Variant 
    
    Dim replacementWord As String 
    
    Dim i As Long 
    
    Dim rng As Range 
    
    ' Array of search words to be replaced 
    
    searchWords = Array("dog", "cat", "bird") 
    
    ' Word to replace the search words 
    
    replacementWord = "pet" 
    
    ' Loop through each search word in the array 
    
    For i = LBound(searchWords) To UBound(searchWords) 
    
        Set rng = ActiveDocument.Content 
    
        With rng.Find 
    
            .ClearFormatting 
    
            .Text = searchWords(i) 
    
            .Replacement.Text = replacementWord 
    
            .MatchWholeWord = True ' Match only whole words 
    
            .MatchCase = False ' Ignore case sensitivity 
    
            .MatchWildcards = False 
    
            .MatchSoundsLike = False 
    
            .MatchAllWordForms = False 
    
            .Execute Replace:=wdReplaceAll  
    
        End With 
    
    Next i 
    

    End Sub

    Best Regards

    Fuad

    1 person found this answer helpful.
    0 comments No comments
  2. HansV 462.6K Reputation points MVP Volunteer Moderator
    2023-07-26T19:05:03+00:00

    Why not replace the Do While ... Loop with

    .Execute Replace:=wdReplaceAll

    1 person found this answer helpful.
    0 comments No comments
  3. HansV 462.6K Reputation points MVP Volunteer Moderator
    2023-07-26T18:47:03+00:00

    You'll have to replace each word separately. If the list of words you want to replace is very long, you might create a macro to do that. But for a few words that would be overkill.

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2023-07-26T18:49:18+00:00

    Hello,

    Thank you for coming to the forum, my name is Fuad, and I will be happy to assist you in the best way I can.

    I have tried many wild card combination, but it is not working with the find and replace dialogue box.

    Do you want a VBA solution?

    All you need to do is replace the words dog, cat and bird with your own words. Note, dog is not the same thing as dogs so, if any of the words have a plural, you will need to include it in the array

    Sub ReplaceMultipleWords() Dim searchWords As Variant Dim replacementWord As String Dim i As Long Dim rng As Range

    ' Array of search words to be replaced searchWords = Array("dog", "cat", "bird")

    ' Word to replace the search words replacementWord = "pet"

    ' Loop through each search word in the array For i = LBound(searchWords) To UBound(searchWords) Set rng = ActiveDocument.Range With rng. Find . ClearFormatting . Text = searchWords(i) . Replacement.Text = replacementWord . MatchWholeWord = True ' Match only whole words . MatchCase = False ' Ignore case sensitivity . MatchWildcards = False . MatchSoundsLike = False . MatchAllWordForms = False

    Do While . Execute(Forward:=True) = True rng. Text = replacementWord rng. Collapse wdCollapseEnd ' Move to the next search Loop End With Next i End Sub

    I kindly await a reply for a follow-up

    Best Regards Fuad

    0 comments No comments