Sam said:
Ok, so I've got that far (thanks for help!). Now my
problem is that I'm trying to replace each instance of a
word, but it stops after the first one. Here's my code:
It's obviosuly something simple that I'm doing wrong. Can
you see what it is?
You need to put the relevant code in a loop like this.
Sub test3()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "SomeWord"
.Forward = True
.Wrap = wdFindStop 'this line is changed
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute 'this line is changed
Selection.Comments.Add Range:=Selection.Range, _
Text:="Here's my comment!
Loop ' This line is added
End Sub
I made the following changes
I've created a Do-Loop structure round the code that searches and adds the
comment
I've changed the Wrap property so that the Find doesn't start again at the
top of the document when it reaches the end.
I've modified the code that actually adds the comment, so that the one line
inserts the text of the comment without the need for a TypeText command and
changing the active pane. That will speed things up quite a bit.
The trick of this is that the Execute method of the Find object returns a
Boolean value which is True if something is found, and False otherwise. That
is used to determine whether you drop out of the loop.
--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com