How to Find Different Texts and Replace with the Same One in Your Word Document

In this article, we will introduce you the way to find different texts and replace with the same one in your Word document.

This article is about how to extend the built-in “Find and Replace” function. So you can find different texts at one time instead of repeating multiple times. And in our previous article, we’ve discussed the approach to find and replace multiple items. You can follow this link to check more: How to Find and Replace Multiple Items in Your Word Document

The above article shows the method to find multiple items and replace each with a different one. But this post is about finding different texts and replace with the same one.Find Different Texts and Replace with the Same One in Your Word Document

Run Word Macro to Find Different Texts and Replace with the Same One

  1. First and foremost, open VBA editor in Word. Click “Developer” tab and then the “Visual Basic”. If the “Developer” tab is not activated, press “Alt+ F11” instead.
  2. Now in VBA editor, click “Normal” on the left column.
  3. Next click “Insert” tab and choose “Module”.Click "Normal"->Click "Insert"->Click "Module"
  4. Open the module with double click.
  5. Then paste following codes there:
Sub FindMultiTextsAndReplaceWithOne()
  Dim strFindText As String
  Dim strReplaceText As String
  Dim nSplitItem As Long
 
  Application.ScreenUpdating = False
 
  ' Enter texts to be found and the new ones in inputboxes.
  strFindText = InputBox("Enter texts to be found here,seperated by comma: ", "Texts to be found")
  strReplaceText = InputBox("Enter new texts here: ", "New Texts")
 
  nSplitItem = UBound(Split(strFindText, ","))
 
  ' Find each piece of text and replace it with new one.
  For nSplitItem = 0 To nSplitItem
    With Selection
      .HomeKey Unit:=wdStory
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = Split(strFindText, ",")(nSplitItem)
        .Replacement.Text = strReplaceText
        .Format = False
        .MatchWholeWord = False
      End With
      Selection.Find.Execute Replace:=wdReplaceAll
    End With
  Next nSplitItem
 
  Application.ScreenUpdating = True
End Sub
  1. Next click “Run” or hit “F5” to execute codes.Paste Codes->Click "Run"
  2. In the first input box popping up, enter texts to be found and separate each with a comma. Remember don’t enter a space after comma.
  3. Then click “OK” to proceed.
  4. And in the second box, input the new text and click “OK”.

Here is the outcome:Enter Texts to Be Found and New Text

You can see the new text keeps the original formatting.

Choose a Sufficient Repairing Tool

Data loss has become quite a topic nowadays. And we can encounter with it anytime. Since data accounts for everything in businesses and personal careers as well, it would be a disaster to loss some critical part of them. Therefore, it’s recommended to pick a specialized docx fix utility in advance. With it, you can minimize the downtime of data disaster and retrieve files back as soon as possible.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including xlsx fix and pdf repair software products. For more information visit www.datanumen.com