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.
Check out The Editorium—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.
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.”
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.
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
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.
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.
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)