MouseMove Show/Hide Shape

iDeals

Board Regular
Joined
Oct 22, 2008
Messages
236
Okay, so I have a MouseMove setup on a label to make a shape visible I aslo have a worksheet_activate to make the shape hidden, however it won't hide the shape. Any ideas?

Code:
Sheets("Sheet1").Shapes("Pentagon 1").Visible = True

Code:
Private Sub Worksheet_Activate()
Sheets("Sheet1").Shapes("Pentagon 1").Visible = False
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Where are you placing the code? The code should be placed in the sheet module...

Code:
Right-click the tab for "Sheet1" > Select "View Code" ...
 
Upvote 0
The code is in the sheet module - I added a worksheet_change code to hide the shape which works but I need it to do it with the MouseMove event which I tried to mimic using the worksheet_activate
 
Upvote 0
It seems to work for me. I'm assuming that you have the "End Sub" statement at the end of the Worksheet_Activate event, and that you've enabled events, correct?
 
Upvote 0
perhaps it is a version problem. I'm using Excel 2010. Which version are you using? This is the code I am using in its entirety

Code:
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Sheets("Sheet1").Shapes("Pentagon 1").Visible = True
End Sub

Private Sub Worksheet_Activate()
Sheets("Sheet1").Shapes("Pentagon 1").Visible = False
End Sub

I'm not sure what you mean by enabling events.
 
Last edited:
Upvote 0
I'm using Excel 2010. I just tested your code by placing them both in the code module for Sheet1, and inserting a label and shape on Sheet1. When I activiate Sheet1, the shape becomes invisible. When I move the mouse over the label, the shape becomes visilble. To ensure that events are enabled, enter the following code in the Immediate Window (Ctrl+G)...

Application.EnableEvents = True
 
Upvote 0
I put the code in the immediate window and it still does not work. The shape because visible when I MouseMove over the label but it does not go back to invisible upon the mouse leaving. Very strange it is working for you running the same code and same version of excel.
 
Upvote 0
I put the code in the immediate window and it still does not work. The shape because visible when I MouseMove over the label but it does not go back to invisible upon the mouse leaving. Very strange it is working for you running the same code and same version of excel.

If you'd like the shape to become visible after the mouse leaves the label, then try the following...

1) Add a second label on Sheet1.

2) Place the second label underneath the first label (in Design Mode, right-click the second label, select Order, and then select Send to Back) and set the height and width so that all sides extend beyond the borders of the first label.

3) Make sure that the label is visible.

4) Remove the caption.

5) Set the BackColor property to 0-fmBackStyleTransparent.

6) Make sure that the code module for Sheet1 contains the following event procedures...

Code:
[FONT=Verdana][COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Label1_MouseMove([COLOR=darkblue]ByVal[/COLOR] Button [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Integer[/COLOR], [COLOR=darkblue]ByVal[/COLOR] Shift [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Integer[/COLOR], [COLOR=darkblue]ByVal[/COLOR] X [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Single[/COLOR], [COLOR=darkblue]ByVal[/COLOR] Y [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Single[/COLOR])[/FONT]
[FONT=Verdana] Me.Shapes("Pentagon 1").Visible = [COLOR=darkblue]True[/COLOR][/FONT]
[FONT=Verdana][COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Label2_MouseMove([COLOR=darkblue]ByVal[/COLOR] Button [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Integer[/COLOR], [COLOR=darkblue]ByVal[/COLOR] Shift [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Integer[/COLOR], [COLOR=darkblue]ByVal[/COLOR] X [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Single[/COLOR], [COLOR=darkblue]ByVal[/COLOR] Y [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Single[/COLOR])[/FONT]
[FONT=Verdana] Me.Shapes("Pentagon 1").Visible = [COLOR=darkblue]False[/COLOR][/FONT]
[FONT=Verdana][COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_Activate()[/FONT]
[FONT=Verdana] Me.Shapes("Pentagon 1").Visible = [COLOR=darkblue]False[/COLOR][/FONT]
[FONT=Verdana][COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]

Hope this helps!
 
Upvote 0
Domenic - good work around with the extra label to hide all shapes. Works great. Only problem is I have a class module for MouseMoves on labels that is no longer working with the addition of these labels with their own MouseMoves. The saga continues. I will touch base with Jaafar to see if he has any ideas as he helped me build the Class Module.
 
Upvote 0
Yeah, I'm not as yet familiar with class modules. So hopefully Jaafar or someone else will be able to provide you with the help you need. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

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