MouseMove Event VBA

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,584
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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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:
Upvote 0
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.
 
Upvote 0
I'm sorry I meant to put False, please see updated code.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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. ?
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,179
Members
448,948
Latest member
spamiki

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