View Single Post
  #11   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Finding a single word via find/replace wildcards

OK I give in on the dictionary

If you have a list of the words you want to change and what you want to
change them to, you could add them to a two column table. Put the word to
find in the left column and the word to replace in the right column. Save
the table as Changes.doc (the name is not important as long as you reflect
it and its path in the following macro and it will work fine with docx
formats). The macro will replace all the first words with the second words
in the current document.

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
'Change the path to reflect your table document
sFname = "D:\My Documents\Test\Changes.doc"
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
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=rFindText, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue) = True
oRng.Text = rReplacement
Loop
End With
Next i
oChanges.Close wdDoNotSaveChanges
End Sub
http://www.gmayor.com/installing_macro.htm

"Paul B." wrote in message
...

Graham: Since I'm also converting "thee's and thou's and thy's",
there's much more to do. And toggling the KJV dictionary would be a
nuisance.