Find and replace Hyperlink text

S

Summer

Word 2002

Need to find and replace certain text in a url in a hyperlink. Seems easy
enough using Find adn Replace but it won't work with a hyperlink that has
display text. I triedusing ALT F9 to display code and run Find and Replace.
It worked to replace text on the screen but it didn't actually change the url
text.

Any thoughts
 
J

Jay Freedman

Summer said:
Word 2002

Need to find and replace certain text in a url in a hyperlink. Seems easy
enough using Find adn Replace but it won't work with a hyperlink that has
display text. I triedusing ALT F9 to display code and run Find and Replace.
It worked to replace text on the screen but it didn't actually change the url
text.

Hi Summer,

I don't know why replacing the field code doesn't change the address,
but using a macro to change the address does change the field code.
<shrug> This sample macro will change any hyperlink that points to
www.grinch.com so it goes to www.whoo.com instead. Note that any
address that doesn't contain the first address won't be changed at
all. In any case, the display text won't change (that's a different
property of the hyperlink, and that could be added to the macro).

Sub ReplaceHyperlinkURL()
Dim oHL As Hyperlink
For Each oHL In ActiveDocument.Hyperlinks
oHL.Address = Replace(oHL.Address, _
"www.grinch.com", "www.whoo.com")
Next oHL
End Sub

If you need instructions, see
http://www.gmayor.com/installing_macro.htm.
 
S

Suzanne S. Barnhill

You have to do this twice, once on the field code and once on the field
display. If you look at the Insert | Hyperlink dialog, you will realize that
the display text and underlying hyperlink can be different. Even when they
are the same, you have to replace each in a separate operation.
 

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