View Single Post
  #12   Report Post  
Posted to microsoft.public.word.docmanagement
Paul B. Paul B. is offline
external usenet poster
 
Posts: 11
Default Finding a single word via find/replace wildcards

Wow, that's an amazing macro. I'm glad to see that such referencing is
possible. I'm frankly not sure which method would be better for me in
this case. This is more compact than the separate find/replace
routines - I think there are five of them - but I'd have to list words
separately rather than use wildcards. I'm going to give this some
thought. Is there a way to set oRng to the current Selection? IAC,
this is a keeper. Thanks.

p.


On Jun 18, 1:01*am, "Graham Mayor" wrote:
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 Subhttp://www.gmayor.com/installing_macro.htm