Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Copying hyperlink including nametag

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry - 17 Oct 2007 03:38 GMT
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
Jay Freedman - 17 Oct 2007 04:13 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.