Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Catching the hyperlink event (Word 2000/SR1)

    How, if possible, does one catch the event that a hyperlink has been clicked. We have a need to catch that event and based on what is contained in the link either direct it to a CD or to the internet for the information that is desired.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Catching the hyperlink event (Word 2000/SR1)

    I don't see that as an event in the object model.

    Maybe there's a way to integrate MACROBUTTON fields with hyperlinks so that they actually run a macro? I don't have time to experiment with that right now, but the idea would be for the macro to read the link from the MACROBUTTON itself so you don't need a different macro for each URL. If the document is protected, I don't think it's possible, because the button does not become part of the Selection, but in a regular document, I think it might be possible.

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Catching the hyperlink event (Word 2000/SR1)

    Jim,

    There is no specific event for that in the object model, but it may be possible to trap it using the application-level WindowSelectionChange event. In the code for that event, you could use something like:

    If Selection.Hyperlinks.Count = 1

    to test whether a hyperlink has been clicked on.

    You could then use the Address and/or TextToDisplay properties of Selection.Hyperlinks(1), to determine which hyperlink has been clicked, and what to do with it.

    The downside to using WindowSelectionChange is that it adds a lot of overhead to your Word application - the event is going to fire every time the selection changes so that's more processing that Word has to do. I think some folks here have averred that they could not tell any decrease in Word's performance when using this, but it's something to be aware of.

    Gary

  4. #4
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Catching the hyperlink event (Word 2000/SR1)

    Thanks. That catchs the HyperLink event but the browser comes up first before the event is handled and one of the things we need to do is, based on the contents of the link, is surpress the browser or not. What we are trying to do is to either go to a CD for information or go to an online web service for information but we want to make that decsion based on what is in the link.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Catching the hyperlink event (Word 2000/SR1)

    If you can "train" your users to use the context (right click) menu insead of clicking on a hyperlink, you can use a macro called HyperlinkOpen to intercept the event that occurs when you right-click on a link and choose "Hyperlink > Open".

    Unfortunately, there doesn't seem to be a built-in command for the code that runs on left-clicking a hyperlink.
    The most likely sounding candidate among the built-in commands -- Sub WebAddress() -- doesn't work in Word2000 (perhaps it does in Word2002?)

    In the macro, the default action would be something like this:
    <pre>Sub HyperlinkOpen()
    ActiveDocument.FollowHyperlink _
    Address:=Selection.Range.Hyperlinks(1).Address, _
    NewWindow:=True, AddHistory:=True
    End Sub</pre>

    But you could add code to follow a link to a file on CD, depending on the Address...

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •