batch Find and Replace for docx files

I need to do a batch Find and Replace using about 12 rules on one .docx file.  (This is a linguistics project.)  Some examples of the rules I am using:

Find underlined not bold ??r and make it underlined bold

Find underlined not bold  [oO][uU]r and make it underlined bold

Find double-underlined not bold * and make it single-underlined not bold

The Find and Replace rules should follow the same format as Word's Find and Replace.

Anyone know of a reliable batch Find and Replace program  that will do this?  Most batch Find and Replace software works on a single Find and Replace Rule applied to multiple files, not to multiple rules applied to a single file.  I need to be able to store the rules.


Maybe would help? If not, you can roll your own with a macro and a table

Create a document with a two column table. Enter the words you want to find in the first column and the formatted versions you wish to replace then with in the second column.  Save the file and put the filename and path where indicated.

Sub ReplaceFromTableList()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oRng As Range
Dim rFindText As Range, rReplacement As Range
Dim i As Long
Dim sFname As String
Dim sAsk As String
    sFname = "D:\My Documents\Test\Changes.docx"
    Set oDoc = ActiveDocument
    Set oChanges = Documents.Open(Filename:=sFname, Visible:=False)
    Set oTable = oChanges.Tables(1)
    For i = 1 To oTable.Rows.Count
        Set oRng = oDoc.Range
        Set rFindText = oTable.Cell(i, 1).Range
        rFindText.End = rFindText.End - 1
        Set rReplacement = oTable.Cell(i, 2).Range
        rReplacement.End = rReplacement.End - 1
        With oRng.Find
            Do While .Execute(findText:=rFindText, _
                              MatchWholeWord:=True, _
                              MatchWildcards:=False, _
                              Forward:=True, _
                              Wrap:=wdFindStop) = True
                sAsk = MsgBox("Replace - " & vbCr & oRng & vbCr + vbCr & _
                              "with - " & vbCr & rReplacement, vbYesNo, _
                              "Replace from Table")

                If sAsk = vbYes Then
                    oRng.FormattedText = rReplacement.FormattedText
                End If
                oRng.Collapse wdCollapseEnd
        End With
    Next i
    oChanges.Close wdDoNotSaveChanges
End Sub

Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.


Question Info

Last updated February 17, 2020 Views 4,982 Applies to: