Wednesday, November 20, 2013

How to trigger FollowHyperlink Event in Excel VBA with blank hyperlinks

Ugg & Lee - Hyperlinks
During a recent project, I just wished to run my Excel VBA app via hyperlinks. VBA has an event "FollowHyperlink" which triggers whenever you click on a hyperlink in your active workbook. But there are two main issues. First, Hyperlink cant be a blank and 2nd, if you provide a valid hyperlink then this event will trigger after url execution. In my case, i only wanted to trap the event without invoking the default browser. I tried to google it for any trick but couldn't found one. Did few experiments and I have finally found a handy way of doing it. :-)

I did few tests but Excel raised error whenever i enter unqualified address.  Then i used some special character combinations. After few attempts, I had finally figured it.

Click here to download a working sample!

So here is how its done.

1) Select any cell having data and right click on it.
2) In the context menu, click hyperlink
3) Text to Display field should be showing your cell data so leave it as is.
4) Press "ScreenTip" button and enter short description about this link. Its always a good idea to inform user about what's beneath their mouse pointer.
5) In the address field, add "?" (without quotes).
This question mark will set the hyperlink as blank without effecting the hyperlink behavior. I think we can call it a ghost hyperlink. :-)
Enhanced by Zemanta

No comments:

Post a Comment