batch replace words in Word 2010

Hello,

I just find I need to modify the specil text which is the name of a task in quite a few word documents as it have been changed now. If it is one document, it's easily to use the “Find and Replace” fuction in word, but there are 30 files at least .

Is there any way to batch replace a special word in multiple documents? Any help will be appreciated.

Comments

  • edited June 3 @ 3:49:15 AM
    Hello,

    You can wirte VBA codes to do that as there is no such fuction in word. Here is a macro you can try. You can see more details at :

    How to Find and Replace Contents in Multiple Word Documents

    Sub FindAndReplaceInFolder()
    Dim objDoc As Document
    Dim strFile As String
    Dim strFolder As String
    Dim strFindText As String
    Dim strReplaceText As String

    ' Pop up input boxes for user to enter folder path, the finding and replacing texts.
    strFolder = InputBox("Enter folder path here:")
    strFile = Dir(strFolder & "\" & "*.docx", vbNormal)
    strFindText = InputBox("Enter finding text here:")
    strReplaceText = InputBox("Enter replacing text here:")

    ' Open each file in the folder to search and replace texts. Save and close the file after the action.
    While strFile <> ""
    Set objDoc = Documents.Open(FileName:=strFolder & "\" & strFile)
    With objDoc
    With Selection
    .HomeKey Unit:=wdStory
    With Selection.Find
    .text = strFindText
    .Replacement.text = strReplaceText
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End With
    objDoc.Save
    objDoc.Close
    strFile = Dir()
    End With
    Wend
    End Sub

Sign In or Register to comment.