VBA with Shapes & textbox events.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, I have textbox and shapes in worksheet, can i make vba run/be activated when the mouse hover over the these object, and can I make different macro run with hovering on different objects? Please help me with the code...

Thanks alot for helping in advance.
 
If you simply want to run a particular code whenever the mouse moves across an ActiveX control, such as a text box, place the following code in the sheet module (or right-click the text box while in Design Mode and select View Code), and try...

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] TextBox1_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=Courier New]    Call YourMacro[/FONT]
[FONT=Courier New][COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR][/FONT]
[FONT=Courier New]



Domenic, this works perfect but it run so many times when the mouse is over the button..and it specially flickers is there a way to stop that?
I tried screenupdating to false and back to true but that does not solve the problem.

Please input.

Pedie
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Instead of calling your macro whenever the cursor moves across your control, how about calling it only when the cursor moves across your control and the left mouse button is pressed? If so, try...

Code:
[font=Verdana][color=darkblue]Private[/color] [color=darkblue]Sub[/color] TextBox1_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])
    [color=darkblue]If[/color] Button = 1 [color=darkblue]Then[/color]
        [color=darkblue]Call[/color] YourMacro
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
[/font]

If you'd like to change the button or buttons which need to be pressed in order to call your macro, here are the settings...

Code:
Value Description 
0 No button is pressed. 
1 The left button is pressed. 
2 The right button is pressed. 
3 The right and left buttons are pressed. 
4 The middle button is pressed. 
5 The middle and left buttons are pressed. 
6 The middle and right buttons are pressed. 
7 All three buttons are pressed.
 
Upvote 0
Domenic, thanks again that was useful information...will have to try again and again...
'll come back with more question...
:)


Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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