VB: Change Mouse Cursor when over a specific cell. 'Hover' vb?

Anonymous
2014-10-20T00:55:48+00:00

hi,  i have been trying to see if there is a way to change a mouse icon when i hover over specific a cell(s).  i wonder if there is a 'hover' vb that can help with that.

i would rather have the same hand icon that occurs when pointing to a hyperlink, but that does not seem to have been made available to us.

if viable, an arrow icon would be acceptable.  i have the following example of vb that works 'as is' to toggle between / test icons:

    If Application.Cursor <> xlDefault Then

      Application.Cursor = xlDefault

    Else

      Application.Cursor = xlNorthwestArrow

    End If

isn't there some kind of 'HOVER' vb that will allow this to happen when over a specific cell.

its use will include a function that was made for a scroll row  'hyperlink' type vb that has:

    If UCase(Left(strFormula, 6)) = UCase("=QLINK") Then

in other words, to activate the hover - change cursor, when hovering over a cell that has the left 6 characters as shown above.

other idea for trying to simulate the cursor:  when using the following formula i get the hand cursor when hovering over the cell.

i would think there should be some vb to simulate the same effect.

=HYPERLINK(AZ573,"T1")

this hyperlink requires a double click, and i wonder if that would work for tricking the situation for a cursor change, when the vb link working on will (hopefully), be a single click.  i have not been able to make work the idea heard for putting a 0,0 reference into a hyperlink, as a null reference, but checking into that.  putting the same cell reference in the hyperlink above, gets an error.  just use ON ERROR GOTO ?

like i was saying,  using the arrow cusor will at least work for now if can get hover? vb help on that..  thanks.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

8 answers

Sort by: Most helpful
  1. Anonymous
    2014-10-20T04:42:35+00:00

    Hi Davexx,

    I confess to not being ambitious enough to digest your previous posts related to this subject. So this may be off target.

    AFAIK, there is no way to detect the mouse-move event for an Excel worksheet in order to know if the mouse pointer is over a specific cell without resorting to something highly invasive such as subclassing. You can capture the selection-change, double-click and right-click events, but not simply the mouse-move event (nor the scroll event). Microsoft has deliberately not exposed these events to VBA.

    Subclassing is a drastic measure. It is highly unlikely your situation would warrant this. It theoretically can be done using VB but in practice doesn't work worth a damn. From what I've read (and in my personal experience) it invariably causes Excel to freeze. This is because VB is too slow a language. To my knowledge, it can only be done satisfactorily using a low-level language such as C.  Even so, this is risky, complicated to implement, and a supreme pain to work with in terms of continued development.

    Suggestion 1

    I've created my own custom hyperlinks as follows. Either do this manually or use code if there are several:

    1)  Place a rectangle over the desired cell.

    2)  Make its fill and border invisible.

    3)  Assign a name using a naming convention so that it can be identified as a hyperlink rectangle.

    4)  Assign a common macro.

    5)  IF there are several, use code to housekeep (adjust positions, delete etc.) if things get out of whack.

    The assigned macro detects the identity of the clicked rectangle using the statement "ActiveSheet.Shapes(Application.Caller)". You then querry the identity of the cell under the rectangle using its TopLeftCell property and read the cell's contents. Your code then does whatever is appropriate.

    ** Note that when a macro is assigned to a shape, when you hold the mouse pointer over the rectangle, the hand pointer appears. Remember, the rectangle cannot be seen.

    Suggestion 2

    Simply remap the arrow keys using "Application.OnKey". I have a workbook that uses this to automatically scroll to the cell found in a table by a custom Lookup function using the key combination "Ctrl+DOWN". The user can automatically return to the original cell using "Ctrl+UP". This functionality is communicated with a cell comment.

    Hope this helps,

    Greg Wilson

    0 comments No comments
  2. Anonymous
    2014-10-20T07:05:02+00:00

    hi,  thanks for the reply.  sorry for the other posts..  i might let my filling in all the facts get away (problem: use to not put much in, get serial replies not enough info but no replies on expanding the post.  i need to be more concise / accurate, but have found adding all the facts to be a good filter on getting ernest replies).

    i get the outline of your post, but not quite the application of it.  am not that fast at vb.

    have to confess this might be just a small item but for work flow, if i can see the mouse has selected the cell i intend to click on for a hyperlink type vb, then i don't have to pay twice the attention to it, in trying to get to the next step..

    not sure what a rectangle is, unless it is some graphic, i would guesse that might be too expensive for all the vb type hyperlinks i will use (called:  =QLINKS($A$200,"name")  will scroll me to line 200..

    so the way i id is the contents of cell left(6 formula having "=QLINK".

    what working on lately is see if can simulate some kind of dead hyperlink in cell to simulate the idea, for a hand cursor,  and if much easier then just a:  xlNorthwestArrow

    next:  still checking a page for a rollover effect using a timer..  see how that goes.

    getting a cusor to change will speed up work anyways.  thanks.

    i didn't quite explain in op, trying to get the vb version for:  (checking so much, not checked this yet)

        =HYPERLINK(AZ573,"T1")    'a double click example, even though single click is on

    if relevant,  checking the vb for a hyperlink,  not familiar with / wrong but:

        Application.Hyperlink (RANGE("AR20"))    '< needs fixing

        Application.FollowHyperlink (     '??

    the question then would be:  is there a syntax for simulating a hyperlink,  instead of the examples seeing for add a hyperlink, which seems is Not what need.  especially? if can make destination 0,0 & make it a double-click?  (which is to say the goal is that the double click would never happen, but the mouse icon change would).

    currently checking:

        If UCase(Left(strFormula, 6)) = UCase("=DLINK") Then

        ActiveWorkbook.FollowHyperlink Address:="", NewWindow:=True '

        'ActiveWorkbook.FollowHyperlink Address:="http://microsoft.com", NewWindow:=True 'orig

        End If

    0 comments No comments
  3. Anonymous
    2014-10-21T01:54:31+00:00

    Davexx,

    I have the feeling I'm missing the point because this is too simple:  Are you aware that native hyperlinks already support scrolling to a location in a worksheet?  If that is all you need then you can use something like the below code example.

    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _

        "Sheet1!A200", TextToDisplay:="QLink(""A200"")"

    To answer your question about if there is syntax for  simulating a hyperlink:  AFAIK, no. The problem is detecting the mouse-move event so that the hand icon appears as soon as the pointer is over the cell without having to click anything. The mouse-move event is not exposed to VBA. There is no way to my knowlege to do this without resorting to subclassing (intercepting windows messages) or putting code in a continuous loop that constantly queries the mouse position. These are not viable options for your situation. The latter (continuous loop code) can only be used in discreet intervals similar to edit mode when you double-click a cell to edit text.

    Greg

    0 comments No comments
  4. Anonymous
    2014-10-21T02:12:29+00:00

    Or do it manually:  Right-click > Hyperlink and select the "Place in This Document" option on the left. See picture...

    0 comments No comments
  5. Anonymous
    2014-10-21T15:47:46+00:00

    may have written a few ideas here, but what think just looking for are more examples on inserting a hyperlink with vb.  both logical & actual,  thanks.

    for the manual insert, i have attempted that. what i see is the link will not stay anchored to an exact cell even if try to use an 'absolute' reference with dollar signs eg:  $A$200.  the destination changes after awhile.  was looking for (still not reacquired online note that said) a 0,0 reference.  working on a few things at once.. 

    ==========

    hi, thanks for the example.  i will check that out.  have to confess i am fairly novice at vb & review can be a bit slow for me;  2:  have my other problems that can slow me down much. 

      - will go with what you said for characteristics on what cannot do.  i have to say i regret can be so minute on testing items up or down..  might cause some friction not intended  :)  for no worries doing work. 

    think my questions can be common for deceptively simple answers needed.  prefer 1 liners where can & variations.  i'll take any examples for vb that installs a hyperlink virtual or other.

    had another idea.  not sure if this concept is something normally done:

      where you can have a formula that sets up the format for eg:  =TEXT(anything,"hh:mm")

    i wonder if there is a method for maybe putting example formula in quotes for best example have:

      making this up:

      Application.formulasimulate.text(hyperlink, "EXAMPLE").go

      example (best one have):    "HYPERLINK(Cell.Selection)"

      - where the characteristics make the hand icon happen,  action requires a double-click & if viable in a single click ennironment, would never happen..

    UPDATE:  should have put formula here, this formula requires a doubleclick to activate (never happen if a singleclick link exists - happens first:  is good,  but will still get the hand pointer).

        =HYPERLINK($BH$573,"T1")    'to find a vb version of this,  skipping the friendly name..


    2ND EXAMPLE might be in alternate method for using a different ICON.ico file / command:

      Application.Cursor = xlNorthwestArrow

    i had in mind where already using (something similar to) activate if click in column:

    Option Explicit

    Private Sub Worksheet_SelectionChange(ByVal Target As RANGE)    '<<  might change this line?

    Set MyRange = Me.RANGE(L2).EntireColumn

    If Target.Cells.Count = 1 And UCase(Left(strFormula, 6)) = UCase("=QLINK") And Not Intersect(Target, MyRange) Is Nothing And Target.Row > RANGE(G7).Row Then

    or is it this line that makes it a click instead of unquote: hover:

    Not Intersect(Target, MyRange)

    Other ideas..

    making some kind of Function for a hyperlink characteristic, that skips the destination.

    etc.

    ==========

    i guesse what looking for are any examples for installing a hyperlink, mostly logical, but both logical & actual.  had been looking but your eg is about the only one that i have / just received..  will take me awhile to digest answers..  situation permitting.  thanks much.

    0 comments No comments