Copying hyperlink including nametag

L

Larry

Hello all, I haven't posted here in quite a while.

The below macro copies the first hyperlink in the document. However, when
the hyperlink includes a nametag, the copy does not include the name tag.
For example, if the first hyperlink in the document is

http://www.mysite.com/xxxx.html#test

what the macro puts in the Clipboard is

http://www.mysite.com/xxxx.html

For whatever reason, the code
ActiveDocument.Hyperlinks(1).Address
does not include the nametag.

Is there any way I can get this macro to copy the nametag if there is one?
Thanks.

Here's the macro:

If ActiveDocument.Hyperlinks.Count = 0 Then
Exit Sub
End If

Dim MyData As DataObject
Dim strURL As String

strURL = ActiveDocument.Hyperlinks(1).Address
Set MyData = New DataObject
MyData.SetText strURL
MyData.PutInClipboard
 
J

Jay Freedman

What you're calling the nametag is in the hyperlink's .SubAddress
property. Try this:

With ActiveDocument.Hyperlinks(1)
strURL = .Address
If Len(.SubAddress) > 0 Then
strURL = strURL & "#" & .SubAddress
End If
End With
 
L

Larry

Jay, as always, thanks so much.

That works. But I still have more work as that macro is only the first of a
set of steps that turn a hyperlink into an html-tagged hyperlink and apply
it to the current word or selected text. In that step, even if the
subaddress is in the link that's been applied to the text, the subaddress is
still left out of the final result, which is the html-tagged link.

I'll see if I can figure this out on my own first.

Larry



Jay Freedman said:
What you're calling the nametag is in the hyperlink's .SubAddress
property. Try this:

With ActiveDocument.Hyperlinks(1)
strURL = .Address
If Len(.SubAddress) > 0 Then
strURL = strURL & "#" & .SubAddress
End If
End With



--
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