Excel VBA - triggering a macro when mouse is hovered off a label

BBxcl

New Member
Joined
Sep 29, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi,
I’m creating a dashboard in excel with a number of different charts. I wanted to add some text boxes at the bottom of each chart to explain what the chart is about but don’t want the text boxes to be visible all the time since it would clutter the dashboard.

I created a label and assigned it a MouseMove event that makes the text box visible when the mouse is moved over it. See code below:

VBA Code:
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
   Sheet2.Shapes(“TextBox 1”).Visible = True
End Sub

The problem is that when the mouse is hovered/moved off the label, the textbox stays visible. I would want to hide the textbox if the mouse is not on top of the label. I’m new to events so I’m not sure if such an event exists. Could anyone please help with this?

Many thanks in advance!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The event you are referring to does not exist. You will have to solve this with another (transparent) label which is placed in Z-order directly under the first label, but which is considerably larger in size. In its mouse move event handler you include code that makes the text box invisible again.
Of course you increase the dimensions of the underlying label with code within the mouse move event handler of the top label which displays the text box.
This approach requires some trial and error, but it's not impossible.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

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