Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink Click event?

Status
Not open for further replies.

JVerdaasdonk

Instructor
Jan 18, 2004
72
NL
Hi,

In my Word document I’ve got a hyperlink that opens an Excel document.

I would like the Word document to close and save it self when I press the hyperlink. The code to close and save the active document I have.

What I need is the code that runs at the click-event of the hyperlinks.

I’ve been looking at the object model of hyperlinks, and I can’t find the event I’m looking for.

Who has an idea?

Regards,
Joost Verdaasdonk
 
I can't find an event to let you trap the hyperlink like that (though Word is not where my VBA strengths lie). My advise would be to use a button on the form. then you can use "FollowHyperlink" to make the hyperlink work, and save and close your file with no problems.

Kyle
 
Thanks Kyle,[wink]

I’ve thought about that method, but it’s not as easy to use as I would hope it to be.

I’m just looking for a code that solves this problem in the way I described.
In this document there is no User form and an Cmd button is not an option.

But thank you for sharing you’re thoughts about this subject! (lets hope there’s a Work around!)

See Yah!
Joost Verdaasdonk
 
Hey, no problem. Sorry I couldn't be of more assistance. Just remember, there doesn't have to be a user form for you to use a command button. You can place one directly onto the document...

Kyle
 
Thanks a bunch Kyle,[upsidedown]

I know this option is available in Word (button on document).
The reason that I want to capture the hyperlink is that I don’t want to let the user know what is happening in the background.

Buttons directly in a document don’t look to nice. (that’s my personal opinion…sorry!)

But I welcome the thought off brainstorming on other options. But they can not be visible. (to the users)

See Yah,
Joost Verdaasdonk
 
Hi Joost,

It's not really any help, but I don't think you can do it. Hyperlinks aren't meant to work that way. If you follow a hyperlink you always have the option to go back.

So, if you can't do it with hyperlinks directly, can you do it some other way by acting on the events which do happen because you've clicked on the hyperlink? I don't think there are any Word Document Events triggered but there should be some Word Application Events when you open an Excel Application - WindowDeactivate at least, but I don't think you can tell that the hyperlink has been clicked. There will also be Excel Events triggered on loading/opening but, again, you won't know that the hyperlink has caused them to fire.

Brainstorming now -- could you create an intermediate hyperlink - a document which is only reached by hyperlinking with a document open macro which did what you wanted and then automatically hyperlinked on when you were ready. Seems a bit awkward to me (and I don't know if it could work without the User being aware) but nothing much I can think of really gets close to what you want. Sorry.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
One alternative...

insert a field into your work doc using macrobutton

insert->field from the menu bar. In the dialogbox enter

=MACROBUTTON MacroName DisplayText

Macroname is the name of the macro to be run
Displaytext is the text that will be displayed (natch)

you can then format the displayed name in underlined blue to look like a hyperlink, then write a code to followHyperlink and then close the doc.

(right clicking on the 'hyperlink' and choosing "toggle field codes" will let you alter the name of the macro that is run or the text)

The upside is that it looks like a normal hyperlink...

The downside is that the user has to doubleclick on the 'hyperlink' to run the macro


It's a shame that word doesn't appear to allow you to assign a macro to a text box (as in excel) as this would run on a single click.

SteveO
 
Hi Steve and Tony,[2thumbsup]

Yep I agree it's a shame that you can't capture a Hyperlink!

But Steve, You're solution is a great alternative!

My Macrobutton looks like this: { MACROBUTTON "VolgenEnWegwezen" "{HYPERLINK "C:\\Documents and Settings\\Joost\\Bureaublad\\als.xls"} }

I triggers the sub VolgenEnWegwezen that saves the active document and closes the aplication!

Yep double clicking is different....but no problems here it's easy getting used to!

Thank's a bunch!

Regards,
Joost Verdaasdonk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top