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.
Method 1: Utilize “Find and Replace” Feature in a Selection
- Firstly, select target text.
- Secondly, press “Ctrl+ H” to open “Find and Replace” box.
- Next enter the finding text in “Find what” text box and the replacing text in “Replace with” box.
- Then click “Replace All” button.
- A box will pop up, asking if you want to continue doing the searching at the rest of a document. Ensure you click “No”.
Method 2: Run VBA Codes to Find and Replace Text in a Selection
- First of all, select a range of document content.
- Next trigger VBA editor by pressing “Alt+ F11”.
- Then click “Normal” and click “Insert”.
- Choose “Module” on the menu.
- Now open the module with double click.
- 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
- Next hit “F5”.
- There will be two input boxes prompting up. Enter the finding and replacing text respectively in two boxes.
- Click “OK” to proceed.
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.
- First, install and run a macro following steps in method 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
- 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.
- Remember to click “OK” to proceed.
Method 4: Run Word Macro to Find and Replace Text in a Section
- Similarly, take the same steps in method 2 to install and run a macro.
- 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
- Remember to enter the section number in the first box. And input finding and replacing texts in the following two boxes.
- 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