Edit/Replace Text within Hyperlinks

T

TOMB

I have a .doc which has about 35 hyperlinks to a shared folder. I would like
to do an edit/replace of "2007" with "2008" across all hyperlinks.

Example:
Hyperlink is
\\MyServer\FolderXXXX\SubFolder\PlanningTools\2007\_Category\2007Priorities
byChannel.ppt

Replace with:
\\MyServer\FolderXXXX\SubFolder\PlanningTools\2008\_Category\2008Priorities
byChannel.ppt

Does anyone know of an easy way to do this? I'd rather not edit each
individually...

Thanks

TOMB
 
J

Jay Freedman

This will do the job. Open the document before running the macro.

Sub demo()
Const sOld = "2007"
Const sNew = "2008"
Dim oHyper As Hyperlink

For Each oHyper In ActiveDocument.Hyperlinks
With oHyper
.Address = Replace(.Address, sOld, sNew)
.TextToDisplay = Replace(.TextToDisplay, sOld, sNew)
End With
Next
End Sub

The .TextToDisplay is what you see in the document, while the .Address is
the URL passed to the browser, and they aren't necessarily the same. The
macro takes care of changing both of them.

If "2007" isn't present in a particular hyperlink, that one won't be
changed. If it's present more than once, as in the example you showed, the
Replace function will change all of them in one shot.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
T

TOMB

Worked perfectly. I will keep this in my bag of tricks for other changes.
Thanks!

TOMB
 

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