Nowadays, I am working with a lot of Unicode text in MS-Word. In documents that I handle, all pieces of the text invariably need editing. And that’s what I do! But there are some commonly occurring mistakes which I have to repeatedly correcting in various documents.
So, I thought it would be great if I could run several find and replace commands in one go. I often use Find and Replace facility of MS Word. Now the question was how to do multiple find and replace operations on one click.
Well, the answer has to involve a macro! Several tasks can be executed in any MS Word document by the way of macros.
A macro is a set of several commands put together in a particular sequence. All you need is to write a macro and then keep running it on the target documents. For multiple find and replace, you can use a module like given below (I found it on Internet):
Sub MultiReplace() Dim StrOld As String, StrNew As String Dim RngFind As Range, RngTxt As Range, i As Long StrOld = "the,quick,brown,fox" StrNew = "The,Quick,Brown,Fox" Set RngTxt = Selection.Range For i = 0 To UBound(Split(StrOld, ",")) Set RngFind = RngTxt.Duplicate With RngFind.Find .ClearFormatting .Replacement.ClearFormatting .Text = Split(StrOld, ",")(i) .Replacement.Text = Split(StrNew, ",")(i) .Format = False .MatchWholeWord = True .MatchAllWordForms = False .MatchWildcards = False .Execute Replace:=wdReplaceAll End With Next End Sub
In this macro program, the comma separated values in StrOld are the items to be replaced. Each item in this list will be replaced by the corresponding value given in StrNew string. Needless to say, both the strings should have equal number of values and obviously the sequence of the values does matter.
You can write this macro by going in the Visual Basic Editor of Microsoft Word.
I keep on writing articles about time saving MS-Word tips. Do subscribe my blog and keep on receiving great tips that will help you achieve greater productivity at work place.
I hope this was useful for you. Please do let me know if you have any questions on this topic. Thank you for using TechWelkin!