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
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
>Hello all, I haven't posted here in quite a while.
>
[quoted text clipped - 28 lines]
> MyData.SetText strURL
> MyData.PutInClipboard
--
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.
Larry - 17 Oct 2007 05:42 GMT
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
> What you're calling the nametag is in the hyperlink's .SubAddress
> property. Try this:
[quoted text clipped - 44 lines]
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.