Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Edit/Replace Text within Hyperlinks

488 views
Skip to first unread message

TOMB

unread,
May 5, 2008, 2:27:01 PM5/5/08
to
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

Jay Freedman

unread,
May 5, 2008, 3:20:06 PM5/5/08
to
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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

TOMB

unread,
May 5, 2008, 5:06:05 PM5/5/08
to
Worked perfectly. I will keep this in my bag of tricks for other changes.
Thanks!

TOMB

0 new messages