K
koryklein
Hello,
I am fairly new to VBA programming and am having trouble figuring out
an error. The following code searches through a word document
highlighting certain words with are being passed to this function. In
addition to the highlighting, I want to add a hyperlink to each word
that is highlighted. I can't seem to set the right anchor. I can't
figure out how to set the anchor on the search word. Thanks in
advance!
CODE:
Sub FindAndHighlight(ByVal rngStory As Word.Range, myYellowWord As
String, NewBackColor As WdColorIndex, NewForeColor As WdColorIndex,
ByVal matchWholeWord As Boolean, myReason As String)
Do Until (rngStory Is Nothing)
With rngStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = myYellowWord
.matchWholeWord = matchWholeWord
While .Execute
rngStory.Hyperlinks.Add Address:="http://www.msn.com/", _
Anchor:=rngSory, _
ScreenTip:=myReason
rngStory.HighlightColorIndex = NewBackColor 'wdYellow
rngStory.Font.ColorIndex = NewForeColor 'wdColorRed
Wend
End With
Set rngStory = rngStory.NextStoryRange
Loop
End Sub
I am fairly new to VBA programming and am having trouble figuring out
an error. The following code searches through a word document
highlighting certain words with are being passed to this function. In
addition to the highlighting, I want to add a hyperlink to each word
that is highlighted. I can't seem to set the right anchor. I can't
figure out how to set the anchor on the search word. Thanks in
advance!
CODE:
Sub FindAndHighlight(ByVal rngStory As Word.Range, myYellowWord As
String, NewBackColor As WdColorIndex, NewForeColor As WdColorIndex,
ByVal matchWholeWord As Boolean, myReason As String)
Do Until (rngStory Is Nothing)
With rngStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = myYellowWord
.matchWholeWord = matchWholeWord
While .Execute
rngStory.Hyperlinks.Add Address:="http://www.msn.com/", _
Anchor:=rngSory, _
ScreenTip:=myReason
rngStory.HighlightColorIndex = NewBackColor 'wdYellow
rngStory.Font.ColorIndex = NewForeColor 'wdColorRed
Wend
End With
Set rngStory = rngStory.NextStoryRange
Loop
End Sub