# Word automatic find/replace based on a table of terms?

**URL:** <https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538>\
**Category:** Factual Questions\
**Created:** [May 24, 2010, 3:48am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538 "2010-05-24T03:48:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koxinga](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@Koxinga](https://boards.straightdope.com/u/Koxinga)\
**Post date:** [May 24, 2010, 3:48am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/1 "2010-05-24T03:48:11Z")

</div>

I don’t know if this will make sense, but I want to figure out how to set up a macro or some other automatic function, preferably in Word, to do a series of find/replace actions.

Specifically, I currently have a Word table of terms to translate from one language to another, mostly technical terms and proper names. Column A has the original language’s terms, and Column B has the corresponding English terms.

When I get a new document to translate, what I’m doing currently is going down the table line by line and manually typing “find” the column A term and “replace” with the column B term. That way, before translating a document I can get all the difficult terms and names out of the way first. It’s less time consuming than going back and looking up each term as I encounter it sequentially in the text, sometimes the same word multiple times.

But I’m constantly adding to the list of terms, and doing this manual find/replace action has become rather laborious as well.

So I’m wondering if there’s some way that I can instruct Word to go through my table automatically and relace each instance of “Column A, row X” with “Column B, row x.” Sort of like VLOOKUP in Excel, except I’m inserting the results into lines of text instead of a nicely ordered table.

Any ideas? If so – much appreciated in advance!

---

<div class="post-metadata">

**Author:** ![Koxinga](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@Koxinga](https://boards.straightdope.com/u/Koxinga)\
**Post date:** [May 25, 2010, 1:32am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/2 "2010-05-25T01:32:51Z")

</div>

Nothin’, huh?

---

<div class="post-metadata">

**Author:** ![K364](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/k364/32/5_2.png) [@K364](https://boards.straightdope.com/u/K364)\
**Post date:** [May 25, 2010, 2:22am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/3 "2010-05-25T02:22:13Z")

</div>

Well, here is a quick and dirty macro that will do the basics of what you want. You put the word pairs in the “Translate” subroutine.

```auto

Sub Translate()
    
    ReplaceOne "one", "un"
    ReplaceOne "One", "Un"
    ReplaceOne "two", "deux"
    ReplaceOne "Two", "Deux"
    ReplaceOne "three", "trois"
    ReplaceOne "Three", "Trois"
    
End Sub

Sub ReplaceOne(sFindWord As String, sReplaceWord As String)
    
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = sFindWord
        .Replacement.Text = sReplaceWord
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

```

---

<div class="post-metadata">

**Author:** ![Koxinga](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@Koxinga](https://boards.straightdope.com/u/Koxinga)\
**Post date:** [May 25, 2010, 2:28am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/4 "2010-05-25T02:28:55Z")

</div>

I appreciate that – I figured that if nothing else I might cobble together some kind of macro --thanks for doing the leg work on that!

I’m guessing that doing something on the basis of a table (either in-document or imported) might be a little bit beyond my capabilities though.

Thanks again!

Koxinga

---

<div class="post-metadata">

**Author:** ![K364](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/k364/32/5_2.png) [@K364](https://boards.straightdope.com/u/K364)\
**Post date:** [May 25, 2010, 2:40am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/5 "2010-05-25T02:40:43Z")

</div>

Koxinga - Are you suggesting that a separate document would have a two-column table holding the “Table of Terms”?

“Table of Terms” isn’t a Word construct like Table of Contents, or Table of Authorites is it?

---

<div class="post-metadata">

**Author:** ![Scarlett67](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/scarlett67/32/7387_2.png) [@Scarlett67](https://boards.straightdope.com/u/Scarlett67)\
**Post date:** [May 25, 2010, 3:05am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/6 "2010-05-25T03:05:50Z")

</div>

Check out [The Editorium](http://www.editorium.com)—the Megareplacer macro will do exactly as you ask. There’s a full-function free trial period.

Disclaimer: I (along with zillions of other power Word users, particularly copyeditors) am merely a very happy customer. I use several Editorium tools every day. And Jack Lyon, the proprietor/macro wizard, provides excellent tech support. Check out his archives and/or buy his book for all kinds of useful tools and nuggets of info.

---

<div class="post-metadata">

**Author:** ![Koxinga](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@Koxinga](https://boards.straightdope.com/u/Koxinga)\
**Post date:** [May 25, 2010, 3:06am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/7 "2010-05-25T03:06:45Z")

</div>

I’m not sure if I’m getting tripped up on the terminology; I didn’t mean anything special by “Table of Terms.”

But yeah, it would be fantastic if I could even have a separate Excel or text file where I could update new names, words, and the equivalent with their corresponding translations, and then when I’m translating a new batch of Chinese text, it can scan one designated file to see what words/names/etc. to “find” and “replace.”

ETA: Thanks Scarlett67, I’ll check that out too.

---

<div class="post-metadata">

**Author:** ![K364](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/k364/32/5_2.png) [@K364](https://boards.straightdope.com/u/K364)\
**Post date:** [May 25, 2010, 3:33am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/8 "2010-05-25T03:33:07Z")

</div>

Ok, this one looks in a separate document (in this case C: emp\TableOfTerms.doc) for a two column table that holds the search/replace word pairs.

```auto

Sub Translate()
    
    Dim docCurrent As Document, docTOT As Document, tabTOT As Table
    Dim I As Integer, sFind As String, sReplace As String
    
    Set docCurrent = ActiveDocument
    Set docTOT = Documents.Open("C:\Temp\TableOfTerms.doc", , True)
    Set tabTOT = docTOT.Tables(1)
    
    For I = 1 To tabTOT.Rows.Count
        sFind = tabTOT.Cell(I, 1).Range.Text
        sFind = Left(sFind, Len(sFind) - 2)
        sReplace = tabTOT.Cell(I, 2).Range.Text
        sReplace = Left(sReplace, Len(sReplace) - 2)
        docCurrent.Activate
        ReplaceOne sFind, sReplace
    Next I
    
    docTOT.Close False
    
End Sub
Sub ReplaceOne(sFindWord As String, sReplaceWord As String)
    
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = sFindWord
        .Replacement.Text = sReplaceWord
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With

```

---

<div class="post-metadata">

**Author:** ![Scarlett67](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/scarlett67/32/7387_2.png) [@Scarlett67](https://boards.straightdope.com/u/Scarlett67)\
**Post date:** [May 25, 2010, 3:54am UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/9 "2010-05-25T03:54:24Z")

</div>

> [@Koxinga](#):
>
> But yeah, it would be fantastic if I could even have a separate Excel or text file where I could update new names, words, and the equivalent with their corresponding translations, and then when I’m translating a new batch of Chinese text, it can scan one designated file to see what words/names/etc. to “find” and “replace.”

That is exactly what Megareplacer does, with lots of nifty options.

I also use it to simply flag (using a character style) terms I _may_ want to change (such as when a client wants “since” used only in the temporal sense, otherwise replace with “because,” so I don’t want to change all of them) or things I want to check for other reasons (I might highlight all instances of “Chapter” and “Figure” so I make sure to check the cross-reference). I have a corresponding macro that selects the next instance of highlighted text and removes the char style, so I can either change it as desired or simply move on.

---

<div class="post-metadata">

**Author:** ![jsoltys](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jsoltys](https://boards.straightdope.com/u/jsoltys)\
**Post date:** [September 10, 2014, 8:01pm UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/10 "2014-09-10T20:01:49Z")

</div>

I have basically 0 coding experience but this is exactly what I need done. I created a new vba module with this and replaced the filename and location. When I run the macro, I get “Run-time error ‘5792’ The file appears to be corrupt” Does this mean the code has something incorrect or is it the word/excel file that has something wrong. I am using office 2010 trying to replace words in a word document from a 2 column table in excel.

> [@K364](#):
>
> Ok, this one looks in a separate document (in this case C: emp\TableOfTerms.doc) for a two column table that holds the search/replace word pairs.
> 
> ```auto
> 
> Sub Translate()
>     
> Dim docCurrent As Document, docTOT As Document, tabTOT As Table
> Dim I As Integer, sFind As String, sReplace As String
>     
> Set docCurrent = ActiveDocument
> Set docTOT = Documents.Open("C:\Temp\TableOfTerms.doc", , True)
> Set tabTOT = docTOT.Tables(1)
>     
> For I = 1 To tabTOT.Rows.Count
> sFind = tabTOT.Cell(I, 1).Range.Text
> sFind = Left(sFind, Len(sFind) - 2)
> sReplace = tabTOT.Cell(I, 2).Range.Text
> sReplace = Left(sReplace, Len(sReplace) - 2)
> docCurrent.Activate
> ReplaceOne sFind, sReplace
> Next I
>     
> docTOT.Close False
>     
> End Sub
> Sub ReplaceOne(sFindWord As String, sReplaceWord As String)
>     
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
> With Selection.Find
> .Text = sFindWord
> .Replacement.Text = sReplaceWord
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = True
> .MatchWholeWord = True
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> 
> ```

---

<div class="post-metadata">

**Author:** ![jsoltys](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jsoltys](https://boards.straightdope.com/u/jsoltys)\
**Post date:** [September 10, 2014, 8:08pm UTC](https://boards.straightdope.com/t/word-automatic-find-replace-based-on-a-table-of-terms/540538/11 "2014-09-10T20:08:50Z")

</div>

let me add to my previous post:

In debug it shows the error in the following line:  
Set docTOT = Documents.Open(“C:\Users\jarek\_soltys\Documents\Auto document generator\Replacement Codes.xlsx”, , True)

Not sure what is wrong there?

> [@jsoltys](#):
>
> I have basically 0 coding experience but this is exactly what I need done. I created a new vba module with this and replaced the filename and location. When I run the macro, I get “Run-time error ‘5792’ The file appears to be corrupt” Does this mean the code has something incorrect or is it the word/excel file that has something wrong. I am using office 2010 trying to replace words in a word document from a 2 column table in excel.
