insert hyperlink address as text after hyperlink address

R

Ron Proschan

I have hyperlinks formatted such that a word or phrase in the sentence is the
hyperlink TextToDisplay -- the hyperlink address is only visible in the
pop-up box. Now I would like to select the hyperlink and insert immediately
after it the TextToDisplay in parentheses, as follows, where "hyperlink" is
the hyperlink.

Existing version
"This is the hyperlink." [where www.microsoft.com is the actual
hyperlink.address]

Desired change:
"This is the hyperlink (www.microsoft.com)."

Is there a way to do this? Thanks very much in advance.

Ron Proschan
 
J

Jay Freedman

I have hyperlinks formatted such that a word or phrase in the sentence is the
hyperlink TextToDisplay -- the hyperlink address is only visible in the
pop-up box. Now I would like to select the hyperlink and insert immediately
after it the TextToDisplay in parentheses, as follows, where "hyperlink" is
the hyperlink.

Existing version
"This is the hyperlink." [where www.microsoft.com is the actual
hyperlink.address]

Desired change:
"This is the hyperlink (www.microsoft.com)."

Is there a way to do this? Thanks very much in advance.

Ron Proschan

Yes, that's fairly simple. Try this:

Sub ExpandHyperLinkAddress()
Dim oHL As Hyperlink
Dim sAddr As String
Dim oRg As Range

With ActiveDocument
For Each oHL In .Hyperlinks
Set oRg = oHL.Range
oRg.Collapse wdCollapseEnd

sAddr = " (" & oHL.Address & ")"
oRg.Text = sAddr
Next
End With
End Sub
 
R

Ron Proschan

Jay,

That works perfectly! Thanks very much!

Ron Proschan

Jay Freedman said:
I have hyperlinks formatted such that a word or phrase in the sentence is the
hyperlink TextToDisplay -- the hyperlink address is only visible in the
pop-up box. Now I would like to select the hyperlink and insert immediately
after it the TextToDisplay in parentheses, as follows, where "hyperlink" is
the hyperlink.

Existing version
"This is the hyperlink." [where www.microsoft.com is the actual
hyperlink.address]

Desired change:
"This is the hyperlink (www.microsoft.com)."

Is there a way to do this? Thanks very much in advance.

Ron Proschan

Yes, that's fairly simple. Try this:

Sub ExpandHyperLinkAddress()
Dim oHL As Hyperlink
Dim sAddr As String
Dim oRg As Range

With ActiveDocument
For Each oHL In .Hyperlinks
Set oRg = oHL.Range
oRg.Collapse wdCollapseEnd

sAddr = " (" & oHL.Address & ")"
oRg.Text = sAddr
Next
End With
End Sub

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

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