+ Reply to Thread
Results 1 to 11 of 11

Detect whether hyperlink formula was clicked/followed

  1. #1
    Registered User
    Join Date
    01-08-2014
    Location
    Bath, UK
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    86

    Detect whether hyperlink formula was clicked/followed

    Is there a way to detect whether a hyperlink formula has been clicked/followed - i.e. the user arrived on the sheet/cell following the hyperlink rather than their own navigation. If they followed the hyperlink, I'd like to run some code. The hyperlink is a volatile one (the result of a Match/Index or Vlookup) rather than something that could be pre-defined.

    Because I've got quite a few hyperlinks in the spreadsheet, I've been using the hyperlink formula rather than manual hyperlinks. I'm aware of some problems that Excel treats these formula hyperlinks differently...

    If it's not possible, and I simply remove the hyperlink formula and show the result of the Match/Index (i.e. the cell value), how would get a macro to go to that result? (e.g. if they double click on the cell they'll be taken there - I'm relatively new to VBA and have been exploring the double click function elsewhere in the spreadsheet).

    Thanks in advance for any help/guidance.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Detect whether hyperlink formula was clicked/followed

    This may work for you. Add code to Thisworkbook object

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    01-08-2014
    Location
    Bath, UK
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    86

    Re: Detect whether hyperlink formula was clicked/followed

    Thanks for the code Andy.

    That works well for most of the cells, but I have a few which are merged - is there a way for it to work with these too? (I don't usually user merged cells, but have inherited a spreadsheet with several).
    When I click a hyperlink formula I get a "Run time error 13 type mismatch" error and the debugger highlights the "If InStr(1, Target.Formula, "HYPERLINK(", vbTextCompare) > 0 Then" section of the code.
    If I click End and click the hyperlink again, I am taken to the destination cell (as expected) but without your message.
    If it makes any difference, the merged cells are merged horizontally (e.g. A1-C1 rather than A1-A3 or A1-C3).

    Also, regarding individual/non-merged cells, if I go back and click on the same hyperlink, I'm taken to the destination correctly but the message doesn't appear. If I click a different cell, it works OK, then if I click the original it works OK. Is there a way to re-set it? I'm not sure how likely it is the user will actually do this though.

    Cheers,
    Graham

  4. #4
    Registered User
    Join Date
    01-08-2014
    Location
    Bath, UK
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    86

    Re: Detect whether hyperlink formula was clicked/followed

    Andy,

    A related query, I believe...

    I have other cells on the sheet which I use a double click event to navigate with. If the user mistakenly double clicks on a hyperlink cell, they are taken to the destination but the cell then goes into edit mode. Is there a way to cancel this?

    Thanks,
    Graham

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Detect whether hyperlink formula was clicked/followed

    You could test just the first cell

    Please Login or Register  to view this content.
    The _BeforeDoubleClick event has a Cancel argument which you can set to true

    False when the event occurs. If the event procedure sets this argument to True, the default double-click action isn't performed when the procedure is finished.

  6. #6
    Registered User
    Join Date
    01-08-2014
    Location
    Bath, UK
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    86

    Re: Detect whether hyperlink formula was clicked/followed

    Sorry for the dely in replying, Andy - that works fine!

    For completeness (and in case anyone else looks at this thread), I've included the completed code I've used (with an additional line to cancel the "edit" if the hyperlkink had been double clicked - is this what you meant, or did you mean to edit the ? (sorry, I'm new to VB)).

    Please Login or Register  to view this content.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Detect whether hyperlink formula was clicked/followed

    The cancel would need to be in the double click event

    Please Login or Register  to view this content.
    The cancel in your code example will have no affect

  8. #8
    Registered User
    Join Date
    01-08-2014
    Location
    Bath, UK
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    86

    Re: Detect whether hyperlink formula was clicked/followed

    Thanks Andy. When it seemed to work, I was misled due to some other code assigned to specific cells which I'd used as a workaround. As the code has been pieced together with bits and pieces (and not as tidy as a seasoned pro would have it), I need to dig a little deeper to find where exactly to insert the line.

    Regarding your earlier code, that works fine if the user clicks once on the hyperlink (as normal), but if I move onto the cell with the hyperlink using the cursor arrows, it initiates a loop with another macro which lasts a couple of minutes (and resembles a crash). The macro itself (to highlight the destination cell on a large sheet) only takes a second to run under normal conditions. Do you know of a way to allow the code to work if the mouse was clicked on the cell, but not if the cursor keys were used?

    Thanks,
    Graham

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Detect whether hyperlink formula was clicked/followed

    I don't know of code.

    As hyperlinks appear to be causing an issue is there any reason my a shape could not be used to act as a more proactive event you could capture. The macro could use the shapes location to then read destination address from a cell.

  10. #10
    Registered User
    Join Date
    01-08-2014
    Location
    Bath, UK
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    86

    Re: Detect whether hyperlink formula was clicked/followed

    For this particular spreadsheet, I was asked to make it as easy as possible for the user (a common request?)... When I started on it, some work had already been done involving manual hyperlinks (at least I think some had already been set up). I then changed these to the hyperlink formulae as there were quite a few and the results/destination cells were volatile results of formulae.

    I got curious about being able to do stuff upon following a hyperlink (e.g. highlight/indicate the cell on a large sheet) and felt at that time I could only do it with a macro - I then started investigation VB (my level is generally record & modify results, rather than being able to program) and found double click events which seemed to work.

    I now feel a little stuck as I've got some double click events (go to the cell in a direct link, or go to a cell I've predefined in the macro)and some hyperlink formulae, but now face this problem with the cursor navigating onto a hyperlink cell (but not actually clicking the hyperlink).

    What do you mean by adding a shape? Would this simply be an auto shape with a macro assigned? Not sure what you mean about using the shape's location either? (again, VB novice, so please forgive me). Can you elaborate a little?

    Thanks,
    Graham

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Detect whether hyperlink formula was clicked/followed

    Yes auto shape. The user clicks the auto shape. Your code can then detect which shape, assuming you have more than 1, was clicked. From there you can determine the location of the shape and could use the contents of a cell, which is at a known location relative to the shape in order to perform the hyper link part.

    So in the example attached. you can change the destination in E6 that the clicking of the shape will take you to.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Add 7 days from today when Hyperlink is clicked
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-24-2013, 04:03 PM
  2. Which hyperlink was clicked and associated shape name
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-22-2010, 05:30 PM
  3. Extracting a row number from where a hyperlink was clicked
    By ggabs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2009, 06:24 AM
  4. Detect which shape was clicked....
    By Thief_ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2005, 12:05 AM
  5. [SOLVED] Detect which shape was clicked?
    By Thief_ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2005, 11:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1