4 Useful Methods to Find and Replace Text in Part of a Word Document

In this document, we are glad to show you 4 useful methods to find and replace text in part of a Word document.

Normally, when we do the “Find and Replace” in Word, the effect is globally. So, today we want to offer you ways to find and replace text in part of a document, such as in a selection, a single page or a specific section.Find and Replace Text in Part of a Word Document

Method 1: Utilize “Find and Replace” Feature in a Selection

  1. Firstly, select target text.
  2. Secondly, press “Ctrl+ H” to open “Find and Replace” box.
  3. Next enter the finding text in “Find what” text box and the replacing text in “Replace with” box.
  4. Then click “Replace All” button.
  5. A box will pop up, asking if you want to continue doing the searching at the rest of a document. Ensure you click “No”.Enter Texts in "Find what" and "Replace with" Text Boxes->Click "Replace All"->Click "No"

Method 2: Run VBA Codes to Find and Replace Text in a Selection

  1. First of all, select a range of document content.
  2. Next trigger VBA editor by pressing “Alt+ F11”.
  3. Then click “Normal” and click “Insert”.
  4. Choose “Module” on the menu.Click "Normal"->Click "Insert"->Click "Module"
  5. Now open the module with double click.
  6. Copy and paste the following codes there:
Sub FindAndReplaceInSelection()
  Dim strFindText As String
  Dim strReplaceText As String
 
  strFindText = InputBox("Enter finding text here:")
  strReplaceText = InputBox("Enter replacing text here:")

  With Selection.Find
    .Text = strFindText
    .Replacement.Text = strReplaceText
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With
  Selection.Find.Execute Replace:=wdReplaceAll
End Sub
  1. Next hit “F5”.Paste Codes->Click "Run"
  2. There will be two input boxes prompting up. Enter the finding and replacing text respectively in two boxes.
  3. Click “OK” to proceed.Enter Text to be Found

You shall achieve the exact same effect as in method 1.

Method 3: Run Word Macro to Find and Replace Text on a Designated Page

Following macro enables you to find and replace text on a specific page.

  1. First, install and run a macro following steps in method 2.
  2. Then replace that macro with this one:
Sub FindAndReplaceInSpecificPage()
  Dim strFindText As String
  Dim strReplaceText As String
  Dim strPageNum As String
  Dim nPageNum As Integer
 
  strPageNum = InputBox("Enter a page number: ")
  nPageNum = Int(strPageNum)
 
  Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=nPageNum
  ActiveDocument.Bookmarks("\page").Range.Select
  strFindText = InputBox("Enter finding text here:")
  strReplaceText = InputBox("Enter replacing text here:")

  With Selection.Find
    .Text = strFindText
    .Replacement.Text = strReplaceText
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With
  Selection.Find.Execute Replace:=wdReplaceAll
End Sub
  1. After running these codes, there will be 3 input boxes. Enter a page number in the first box, and input the finding text in the second, and type replacing text in the third.
  2. Remember to click “OK” to proceed.Enter a Page Number ->Click "OK"

Method 4: Run Word Macro to Find and Replace Text in a Section

  1. Similarly, take the same steps in method 2 to install and run a macro.
  2. Only this time use this macro instead:
Sub FindAndReplaceInSection()
  Dim strFindText As String
  Dim strReplaceText As String
  Dim strSectionNum As String
  Dim nSectionNum As Integer
 
  strSectionNum = InputBox("Enter a section number: ")
  nSectionNum = Int(strSectionNum)
 
  Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=1, Name:=nSectionNum
  ActiveDocument.Sections(nSectionNum).Range.Select
  strFindText = InputBox("Enter finding text here:")
  strReplaceText = InputBox("Enter replacing text here:")

  With Selection.Find
    .Text = strFindText
    .Replacement.Text = strReplaceText
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
  End With
  Selection.Find.Execute Replace:=wdReplaceAll
End Sub
  1. Remember to enter the section number in the first box. And input finding and replacing texts in the following two boxes.
  2. Still, click “OK” to proceed.

Cope with Word Issues

There can be many kinds of problems occurring in your document. Some are easy to handle, while others are more severe which may lead to Word corruption. In such scenario, you must get a repair tool as soon as possible as to rescue your data.

Author Introduction:

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

Leave a Reply

Your email address will not be published. Required fields are marked *