C
Casey Mac
Greetings.
I have some code that is going in a contiunious loop.
I want to find some text
Replace it with a hyperlink
Then change the display name of the link
But what happens is that if the display name is the same as the link i want
to find it keeps going around in circles.
If there is something that can be done to it i would really appreciated it .
Thanks
Sub FindAndReplaceWithHypertext()
Dim rngReplace As Word.Range
Dim rngFound As Word.Range
Dim szFindTerm As String
Dim szReplaceHL As String
Dim szTexttoDP As String
szFindTerm = InputBox("Enter the word you wish to replace with a
hyperlink:")
szReplaceHL = InputBox("Enter Adobe File Name:")
szTexttoDP = InputBox("Enter HyperLink Display Name")
Set rngReplace = ActiveDocument.Content
With rngReplace.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = szFindTerm
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
' Find all occurrences in the document
Do While .Execute
' Create and use a totally independent range object
Set rngFound = rngReplace.Duplicate
' Replace sought text with hyperlink
rngFound.Text = vbNullString
ActiveDocument.Hyperlinks.Add rngFound, szReplaceHL, _
TextToDisplay:=szTexttoDP
' Resume the search after the text that we just found
rngReplace.Collapse wdCollapseEnd
Loop
End With
End Sub
I have some code that is going in a contiunious loop.
I want to find some text
Replace it with a hyperlink
Then change the display name of the link
But what happens is that if the display name is the same as the link i want
to find it keeps going around in circles.
If there is something that can be done to it i would really appreciated it .
Thanks
Sub FindAndReplaceWithHypertext()
Dim rngReplace As Word.Range
Dim rngFound As Word.Range
Dim szFindTerm As String
Dim szReplaceHL As String
Dim szTexttoDP As String
szFindTerm = InputBox("Enter the word you wish to replace with a
hyperlink:")
szReplaceHL = InputBox("Enter Adobe File Name:")
szTexttoDP = InputBox("Enter HyperLink Display Name")
Set rngReplace = ActiveDocument.Content
With rngReplace.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = szFindTerm
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
' Find all occurrences in the document
Do While .Execute
' Create and use a totally independent range object
Set rngFound = rngReplace.Duplicate
' Replace sought text with hyperlink
rngFound.Text = vbNullString
ActiveDocument.Hyperlinks.Add rngFound, szReplaceHL, _
TextToDisplay:=szTexttoDP
' Resume the search after the text that we just found
rngReplace.Collapse wdCollapseEnd
Loop
End With
End Sub