Find and Comment

S

Scott Parker

I used MS Word and recorded a macro which would find a specific word, in this case ?internet? and comment. However, if the word does not exist in the document then I get an error. Can anyone tell me how to add error handling or an IF statement?

' Find and Add Comment
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "internet"
.Replacement.Text = "internet"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Comments.Add Range:=Selection.Range
Selection.TypeText Text:="Capitalize Internet as the worldwide communication network"


EggHeadCafe - Software Developer Portal of Choice
C# Speech Recognition Stock Quote app with SAPI
http://www.eggheadcafe.com/tutorial...bd-7da8bfcd6bca/c-speech-recognition-sto.aspx
 
G

Graham Mayor

I suspect the following is closer to what you envisaged

Dim orng As Range
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Text = "internet"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute
Selection.Comments.Add Range:=Selection.Range, _
Text:="Capitalize Internet as the worldwide communication network"
Loop


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Scott Parker

Yes, that is what I envisioned. It works wonderful.
Thank you.



Graham Mayor wrote:

I suspect the following is closer to what you envisagedDim orng As
21-Oct-09

I suspect the following is closer to what you envisaged

Dim orng As Range
Selection.HomeKey wdStory
With Selection.Find
...ClearFormatting
...Text = "internet"
...Forward = True
...Wrap = wdFindContinue
...Format = True
...MatchCase = True
...MatchWholeWord = True
...MatchWildcards = False
...MatchSoundsLike = False
...MatchAllWordForms = False
End With
Do While Selection.Find.Execute
Selection.Comments.Add Range:=Selection.Range, _
Text:="Capitalize Internet as the worldwide communication network"
Loop


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Scott Parker wrote:

Previous Posts In This Thread:

EggHeadCafe - Software Developer Portal of Choice
Painting the Canvas with Silverlight 2.0
http://www.eggheadcafe.com/tutorial...4e-619dac0b86b8/painting-the-canvas-with.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top