MouseMove Event VBA

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,443
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Private Sub Chkbox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  Dim i As Integer
Me.label1.Visible = True
End Sub

VBA Code:
Private Sub UserForm_Initialize()
Me.Label1.Visible = False
End Sub

I wanted to make the label1 visible when i hover my mouse on the Checkbox. However, after using the above code, the moment my mouse hovers over the checkbox, the mouse points disappears. The label never appears.
Please suggest.

P.S. : When I remove the label1.visible = false from form's Initialize event, the label is visible when the form is launched. However, the moment I hover my mouse on the checkbox, the label disappears. So something opposite of what I expect is happening here.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

VBE313

Well-known Member
Joined
Mar 22, 2019
Messages
686
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
     Me.Label1.Visible = False
End Sub
 
Last edited:

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,443
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
     Me.Label1.Visible = True
End Sub
The above codes makes the label disappear the moment I hover on the userform. I also didn't understand why you use Userform event instead of Checkbox event because as mentioned in Post # 1, I want to make the label visible when I hover the mouse on the checkbox.
 

VBE313

Well-known Member
Joined
Mar 22, 2019
Messages
686
Office Version
  1. 365
Platform
  1. Windows
I'm sorry I meant to put False, please see updated code.
 

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,443
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

I'm sorry I meant to put False, please see updated code.
thanks for responding. I tried you code, but the result is same i.e. the label disappears the moment I hover my mouse anywhere on the userform.
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,079
When do you want the label to disappear?

This code will show the label when one hovers over the checkbox. and it will stay visible until one clicks on the label.

VBA Code:
Private Sub CheckBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Me.Label1.Visible = True
End Sub

Private Sub Label1_Click()
    Me.Label1.Visible = False
End Sub

Private Sub UserForm_Initialize()
    'Me.CheckBox1.BackColor = 0
    Me.Label1.Visible = False
End Sub

Note that the checkbox control is larger than the square for the X, it can be quite large. The commented out line in my code will show how big it is.
 

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,443
Office Version
  1. 365
Platform
  1. Windows
When do you want the label to disappear?

This code will show the label when one hovers over the checkbox. and it will stay visible until one clicks on the label.

VBA Code:
Private Sub CheckBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Me.Label1.Visible = True
End Sub

Private Sub Label1_Click()
    Me.Label1.Visible = False
End Sub

Private Sub UserForm_Initialize()
    'Me.CheckBox1.BackColor = 0
    Me.Label1.Visible = False
End Sub

Note that the checkbox control is larger than the square for the X, it can be quite large. The commented out line in my code will show how big it is.
Thanks mickerickson, it worked. I wonder why it wasn't working earlier, even though I used the same code in Post 1. 🤔
 

Forum statistics

Threads
1,147,498
Messages
5,741,505
Members
423,663
Latest member
kaveh87rsh

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
Top