Detecting when mouse has left userform

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
Is there a way to determine if the mouse has left the userform? I currently have buttons on the edge of my userform and they have mousemove events to highlight them when hovered. The problem is if the cursor goes off the userform from the edge then they stay hovered since no userform_mousemove event is triggered which uncolors them. So my question is how can i detect when the mouse leaves the userform and if this is not possible then maybe there is a better way to determine if the mouse is not hovering over the button anymore?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
That is a problem with MouseMove... it can easily be fooled by moving the mouse very fast. If you tell us the names of your buttons, how each is being highlighted (assuming you highlight them each differently) and what the unhighlighted condition is, I see if I can give you code to overcome the problem (I am not 100% sure I can, but I need that information in order to try).
 
Upvote 0
I have many buttons but I have narrowed it to 2 of them to make this simple. When you click the button it saves it as the last button clicked and it turns red. Now when you hover over the last non clicked button then it shoudl turn a dark red which is the hover effect. So these buttons are literally on the edge of the userform so moving the mouse to fast to the left really doesnt trigger the userform event to unhighlight the highlighted one.

Code:
'Creating the hover effects for main menu on left navigation
'&H0& is a non selected menu item and vbRed is the hovered item
Private Sub ToDoListButton_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    'We want to make sure that the last button clicked does not get turned back to regular black
    If Not LastButtonHighlighted.Name = LastButt*******ed.Name Then
        LastButtonHighlighted.BackColor = &H0&
    End If
    'We make sure the highlighted items are all darker red
    If Not LastButt*******ed.Name = ToDoListButton.Name Then
        ToDoListButton.BackColor = &H80&
    End If
    Set LastButtonHighlighted = ToDoListButton
End Sub
Private Sub MyReviewsButton_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    'MsgBox LastButtonHighlighted.Name & "" & LastButt*******ed.Name
    If Not LastButtonHighlighted.Name = LastButt*******ed.Name Then
        LastButtonHighlighted.BackColor = &H0&
    End If
    If Not LastButt*******ed.Name = MyReviewsButton.Name Then
        MyReviewsButton.BackColor = &H80&
    End If
    Set LastButtonHighlighted = MyReviewsButton
End Sub
'Left Navigation clicking options
Private Sub ToDoListButton_Click()
    
    'Hide Last Page
    LastPageVisited.Visible = False
    
    'We track last button highlighted so that it is set back to normal color since new one is highlighted.
    LastButt*******ed.BackColor = &H0&
    Set LastButt*******ed = ToDoListButton
    ToDoListButton.BackColor = vbRed
    
    'Change header label to name
    HeaderLabel.Caption = "To Do List"
    
    'Make this frame visible
    ToDoListFrame.Visible = True
    
    'Set this to be the new last page visited
    Set LastPageVisited = ToDoListFrame
End Sub
Private Sub MyReviewsButton_Click()


    'Hide Last Page
    LastPageVisited.Visible = False
    
    'We track last button highlighted so that it is set back to normal color since new one is highlighted.
    LastButt*******ed.BackColor = &H0&
    Set LastButt*******ed = MyReviewsButton
    MyReviewsButton.BackColor = vbRed
    'Change header label to name
    HeaderLabel.Caption = "My Reviews"
    
    'Make this frame visible
    MyReviewsFrame.Visible = True
    
    'Set this to be the new last page visited
    Set LastPageVisited = MyReviewsFrame
    
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If Not LastButtonHighlighted.Name = LastButt*******ed.Name Then
        LastButtonHighlighted.BackColor = &H0&
    End If
End Sub
 
Last edited:
Upvote 0
As Rick said, relying on the userform _mousemove event can be rather slow.. Plus if the button happens to be located on the edge of the userform then there is no way of restoring the button's initial color when the mouse has left the form.

In my opinion, for a smooth/faster and reliable pseudo Mouse_Leave event, you are probably better off using a couple of API functions .

Also, in order to use a generic routine that is shared by all commandbuttons on the userform, you can add a Class module which is what I am suggesting here .

Steps:

1- Add a new Class Module to your project, give the class the name of CMouseLeave and place the following code in its module :

Code:
Option Explicit

Public WithEvents Btn As MSForms.CommandButton

Private Type POINTAPI
        X As Long
        Y As Long
End Type

[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If"]#If[/URL]  VBA7 Then
    Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
    [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If"]#If[/URL]  Win64 Then
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
    [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else"]#Else[/URL] 
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
    [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End"]#End[/URL]  If
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else"]#Else[/URL] 
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End"]#End[/URL]  If

Private Const CHILDID_SELF = &H0&
Private Const HIGHLIGHT_COLOR As Long = &HFF&  'red

Private Sub Btn_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    Dim tCurPos As POINTAPI
    Dim oIA As IAccessible
    Dim vKid  As Variant
    
    On Error Resume Next
    With Btn
        If .Parent.Tag = "" Then
            If .Tag = "" Then Btn.Tag = .BackColor
            If .BackColor <> HIGHLIGHT_COLOR Then .BackColor = HIGHLIGHT_COLOR
            Do
                .Parent.Tag = "looping"
                GetCursorPos tCurPos
                [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If"]#If[/URL]  Win64 Then
                    Dim Ptr As LongPtr
                    CopyMemory Ptr, tCurPos, LenB(tCurPos)
                    Call AccessibleObjectFromPoint(Ptr, oIA, vKid)
                [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else"]#Else[/URL] 
                    Call AccessibleObjectFromPoint(tCurPos.X, tCurPos.Y, oIA, vKid)
                [URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End"]#End[/URL]  If
                DoEvents
            Loop Until oIA.accName(CHILDID_SELF) <> .Caption
            Call OnMouseLeave(Btn)
        End If
    End With
 
End Sub

Private Sub OnMouseLeave(ByVal Button As CommandButton)
    Button.BackColor = (Button.Tag)
    Button.Parent.Tag = ""
    
[B][COLOR=#008000]    'other code goes here..[/COLOR][/B]
End Sub

2- Place the following code in the Userform module:
Code:
Option Explicit

Private oCol As New Collection
    
Private Sub UserForm_Initialize()
    Dim oCtl As Control
    Dim oClass As CMouseLeave
    For Each oCtl In Me.Controls
        If TypeOf oCtl Is CommandButton Then
            Set oClass = New CMouseLeave
            Set oClass.Btn = oCtl
            oCol.Add oClass
        End If
    Next
End Sub

The Class code will highlight all the commandbuttons on the userform in RED when these are mouse hovered.. Change the value of the HIGHLIGHT_COLOR Constant declared in the declarartions area of the class module to the color of your choice.
 
Last edited:
Upvote 0
The solution works great however there is one thing I am trying to get to work. When you click a button it turns vbRed (active menu item) but when you hover over other items they should become &H80& 'dark red . The thing is as of now if I click a button it turns vbred but right when i hover off it shifts back to black where it should stay vbRed. Also, if a button is already vbRed then it should not change colors given it is alraedy the most active menu item that I am on. Any help editing your code would be great since as of now my modifications are working to it.

Rich (BB code):
Option Explicit


Public WithEvents Btn As MSForms.CommandButton


Private Type POINTAPI
        X As Long
        Y As Long
End Type


#If  VBA7 Then
    Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
    #If  Win64 Then
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
    #Else 
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
    #End  If
#Else 
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
#End  If


Private Const CHILDID_SELF = &H0&
Private Const HIGHLIGHT_COLOR As Long = &H80&  'Dark red


Private Sub Btn_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    Dim tCurPos As POINTAPI
    Dim oIA As IAccessible
    Dim vKid  As Variant
    
    On Error Resume Next
    With Btn
        If .Parent.Tag = "" Then
            If .Tag = "" Then Btn.Tag = .BackColor
            If .BackColor <> vbRed Then .BackColor = HIGHLIGHT_COLOR
            Do
                .Parent.Tag = "looping"
                GetCursorPos tCurPos
                #If  Win64 Then
                    Dim Ptr As LongPtr
                    CopyMemory Ptr, tCurPos, LenB(tCurPos)
                    Call AccessibleObjectFromPoint(Ptr, oIA, vKid)
                #Else 
                    Call AccessibleObjectFromPoint(tCurPos.X, tCurPos.Y, oIA, vKid)
                #End  If
                DoEvents
            Loop Until oIA.accName(CHILDID_SELF) <> .Caption
            Call OnMouseLeave(Btn)
        End If
    End With
 
End Sub


Private Sub OnMouseLeave(ByVal Button As CommandButton)
    Button.BackColor = (Button.Tag)
    Button.Parent.Tag = ""
    
    'other code goes here..
End Sub
 
Last edited:
Upvote 0
The solution works great however there is one thing I am trying to get to work. When you click a button it turns vbRed (active menu item) but when you hover over other items they should become &H80& 'dark red . The thing is as of now if I click a button it turns vbred but right when i hover off it shifts back to black where it should stay vbRed. Also, if a button is already vbRed then it should not change colors. Any help editing your code would be great since as of now my modifications are working to it.

Rich (BB code):
Option Explicit


Public WithEvents Btn As MSForms.CommandButton


Private Type POINTAPI
        X As Long
        Y As Long
End Type


#If  VBA7 Then
    Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
    #If  Win64 Then
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
    #Else 
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
    #End  If
#Else 
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
#End  If


Private Const CHILDID_SELF = &H0&
Private Const HIGHLIGHT_COLOR As Long = &H80&  'Dark red


Private Sub Btn_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    Dim tCurPos As POINTAPI
    Dim oIA As IAccessible
    Dim vKid  As Variant
    
    On Error Resume Next
    With Btn
        If .Parent.Tag = "" Then
            If .Tag = "" Then Btn.Tag = .BackColor
            If .BackColor <> vbRed Then .BackColor = HIGHLIGHT_COLOR
            Do
                .Parent.Tag = "looping"
                GetCursorPos tCurPos
                #If  Win64 Then
                    Dim Ptr As LongPtr
                    CopyMemory Ptr, tCurPos, LenB(tCurPos)
                    Call AccessibleObjectFromPoint(Ptr, oIA, vKid)
                #Else 
                    Call AccessibleObjectFromPoint(tCurPos.X, tCurPos.Y, oIA, vKid)
                #End  If
                DoEvents
            Loop Until oIA.accName(CHILDID_SELF) <> .Caption
            Call OnMouseLeave(Btn)
        End If
    End With
 
End Sub


Private Sub OnMouseLeave(ByVal Button As CommandButton)
    Button.BackColor = (Button.Tag)
    Button.Parent.Tag = ""
    
    'other code goes here..
End Sub
 
Upvote 0
I think I got it working. Do you see any problems with the modification?

Rich (BB code):
Option Explicit


Public WithEvents Btn As MSForms.CommandButton


Private Type POINTAPI
        X As Long
        Y As Long
End Type


#If  VBA7 Then
    Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
    #If  Win64 Then
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
    #Else 
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
    #End  If
#Else 
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
#End  If


Private Const CHILDID_SELF = &H0&
Private Const HIGHLIGHT_COLOR As Long = &H80&  'Dark red


Private Sub Btn_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    Dim tCurPos As POINTAPI
    Dim oIA As IAccessible
    Dim vKid  As Variant
    
    On Error Resume Next
    With Btn
        If .Parent.Tag = "" Then
            If .Tag = "" Then Btn.Tag = .BackColor
            If .BackColor <> vbRed And .BackColor <> HIGHLIGHT_COLOR Then .BackColor = HIGHLIGHT_COLOR
            Do
                .Parent.Tag = "looping"
                GetCursorPos tCurPos
                #If  Win64 Then
                    Dim Ptr As LongPtr
                    CopyMemory Ptr, tCurPos, LenB(tCurPos)
                    Call AccessibleObjectFromPoint(Ptr, oIA, vKid)
                #Else 
                    Call AccessibleObjectFromPoint(tCurPos.X, tCurPos.Y, oIA, vKid)
                #End  If
                DoEvents
            Loop Until oIA.accName(CHILDID_SELF) <> .Caption
            Call OnMouseLeave(Btn)
        End If
    End With
 
End Sub


Private Sub OnMouseLeave(ByVal Button As CommandButton)


    If Button.BackColor <> vbRed Then Button.BackColor = (Button.Tag)
    Button.Parent.Tag = ""
    
    'other code goes here..
End Sub
 
Upvote 0
That code you posted wont do what you want :

Try replacing the class code with this new code :

Code:
Option Explicit

Public WithEvents Btn As MSForms.CommandButton

Private Type POINTAPI
        X As Long
        Y As Long
End Type

#If VBA7 Then
    Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
    #If Win64 Then
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
    #Else
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
    #End If
#Else
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
#End If

Private Const CHILDID_SELF = &H0&
Private Const HOVER_COLOR As Long = &H80&   [B][COLOR=#008000]'Dark Red[/COLOR][/B]
Private Const ACTIVE_COLOR As Long = &HFF&  [B][COLOR=#008000]'Bright Red[/COLOR][/B]

Private bClicked As Boolean


Private Sub Btn_Click()

    Dim oCtl As Control
    
    For Each oCtl In Btn.Parent.Controls
        If TypeOf oCtl Is CommandButton Then
            If oCtl.Tag <> "" Then
                oCtl.BackColor = Val(oCtl.Tag)
            End If
        End If
    Next
    Btn.BackColor = ACTIVE_COLOR
    bClicked = True

    [B][COLOR=#008000]'other code here ...[/COLOR][/B]
End Sub

Private Sub Btn_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    
    Dim tCurPos As POINTAPI
    Dim oIA As IAccessible
    Dim vKid  As Variant
    
    On Error Resume Next
    With Btn
        If .BackColor = ACTIVE_COLOR Then Exit Sub
        If .Parent.Tag = "" Then
            If .Tag = "" Then Btn.Tag = .BackColor
            If .BackColor <> HOVER_COLOR Then .BackColor = HOVER_COLOR
            .Parent.Tag = "looping"
            Do
                GetCursorPos tCurPos
                #If Win64 Then
                    Dim Ptr As LongPtr
                    CopyMemory Ptr, tCurPos, LenB(tCurPos)
                    Call AccessibleObjectFromPoint(Ptr, oIA, vKid)
                #Else
                    Call AccessibleObjectFromPoint(tCurPos.X, tCurPos.Y, oIA, vKid)
                #End If
                DoEvents
            Loop Until oIA.accName(CHILDID_SELF) <> .Caption Or bClicked
            bClicked = False
            Call OnMouseLeave(Btn)
        End If
    End With
 
End Sub

Private Sub OnMouseLeave(ByVal Button As CommandButton)
    
    Button.Parent.Tag = ""
    If Button.BackColor <> ACTIVE_COLOR Then
        Button.BackColor = Button.Tag
    End If
 
    [B][COLOR=#008000]'other code goes here..[/COLOR][/B]
End Sub
 
Last edited:
Upvote 0
I have been working on something similar and cannot seem to get it to work. Imagine I have a black background with 4 different labels with the NameABC_Header in white. When I click on one I have click events that change the forecolor of the word to vbRed along with some other code in the form module. However I want to add hover effects for any of those _Header words that arent vbRed. So I tried to modify the earlier code of this thread to do so but as of now if I hover over one of the words it goes dark red and just stays at that color regardless of leaving it (should go back to the child color of white) and no other words change colors when hovering.

Code so far:

form code in initialize
Rich (BB code):
    'Add Highlighting effect to buttons    Dim oCtl As Control
    Dim oClass As CMouseLeaveLabels
    For Each oCtl In Me.Controls
        If Right(oCtl.Name, 7) = "_Header" Then
            Set oClass = New CMouseLeaveLabels
            Set oClass.lbl = oCtl
            HighlightLabelCollection.Add oClass
        End If
    Next

Class CMouseLeavesLabels
Rich (BB code):
Option Explicit


Public WithEvents lbl As MSForms.Label


Private Type POINTAPI
        X As Long
        Y As Long
End Type


#If  VBA7 Then
    Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
    #If  Win64 Then
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
    #Else 
         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
    #End  If
#Else 
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
#End  If


Private Const CHILDID_SELF = &H8000000F
Private Const HIGHLIGHT_COLOR As Long = &H80&  'Dark red


Private Sub lbl_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)


    Dim tCurPos As POINTAPI
    Dim oIA As IAccessible
    Dim vKid  As Variant
    
    On Error Resume Next
    With lbl
        If .Parent.Tag = "" Then
            If .Tag = "" Then lbl.Tag = .ForeColor
            If .ForeColor <> vbRed And .ForeColor <> HIGHLIGHT_COLOR Then .ForeColor = HIGHLIGHT_COLOR
            Do
                .Parent.Tag = "looping"
                GetCursorPos tCurPos
                #If  Win64 Then
                    Dim Ptr As LongPtr
                    CopyMemory Ptr, tCurPos, LenB(tCurPos)
                    Call AccessibleObjectFromPoint(Ptr, oIA, vKid)
                #Else 
                    Call AccessibleObjectFromPoint(tCurPos.X, tCurPos.Y, oIA, vKid)
                #End  If
                DoEvents
            Loop Until oIA.accName(CHILDID_SELF) <> .Caption
            Call OnMouseLeaveLabel(lbl)
        End If
    End With
 
End Sub


Private Sub OnMouseLeaveLabel(ByVal Button As Label)
MsgBox "Test"
    If Button.ForeColor <> vbRed Then Button.ForeColor = (Button.Tag)
    Button.Parent.Tag = ""
    
    'other code goes here..
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top