Adding a new event

Haluk

Rules Violation
Joined
Oct 26, 2002
Messages
1,075
Hi;

is it possible to add a new event such as "Mouse_Move" to the "Worksheet" object by creating a class module or something else ?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi Raider,

It is possible to define your own events (see Event and RaiseEvent statements in the VBA helps), but this capability is limited to triggering on things that your own code makes happen. It cannot be used to create an event that triggers when something happens that is outside the control of your code (e.g., a Mouse_Move event) where one doesn't already exist. There are numerous events that I wish existed that simply don't.
 
Upvote 0
Hi Raider
What do you want this Event for ??
Is this to detect when the cursor is over
a certain object or cell ??
There maybe a way....
 
Upvote 0
Hi Ivan;

i've used the Mouse_Over event to change the background color for a commandbutton on a worksheet, when the pointer is on the button. So, when the pointer is not over the commandbutton object i.e, if it is on the worksheet somewhere, i want to recall the commandbutton's original backcolor.

Regards,

Edit: None of the cells may be selected while the pointer is not on the commandbutton object.
This message was edited by Raider on 2002-11-05 02:10
 
Upvote 0
Give it a try this until you are waiting Ivan's special answer. :biggrin:
How about use LostFocus event. But need to activate cells to recall the commandbutton's original backcolor.

<PRE><FONT color=red>Option Explicit</FONT>



<FONT color=red>Private <FONT color=red>Sub </FONT></FONT>CommandButton1_MouseMove(<FONT color=red>ByVal</FONT> Button <FONT color=red>As</FONT><FONT color=red> Integer</FONT>, _

<FONT color=red>ByVal</FONT> Shift <FONT color=red>As</FONT><FONT color=red> Integer</FONT>, _

<FONT color=red>ByVal</FONT> X <FONT color=red>As</FONT><FONT color=red> Single</FONT>, _

<FONT color=red>ByVal</FONT> Y <FONT color=red>As</FONT><FONT color=red> Single</FONT>)

CommandButton1.BackColor = &HFFFF&

CommandButton1.Activate

<FONT color=red>End Sub</FONT>



<FONT color=red>Private <FONT color=red>Sub </FONT></FONT>CommandButton1_LostFocus()

CommandButton1.BackColor = &H8000000F

<FONT color=red>End Sub</FONT>
</PRE>
 
Upvote 0
Hi again;

For the time being i've created the following lines to change the backcolor of the commandbutton object when the pointer of the mouse comes over the button object. But the problem is, the color is not static. i guess some sort of refreshing is needed.

Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
xx = CommandButton1.Width
yy = CommandButton1.Height
CommandButton1.BackColor = &HFF&
DoEvents
If xx < 0.1 * X Or xx > 0.9 * X Or yy < 0.1 * Y Or yy > 0.9 * Y Then CommandButton1.BackColor = &H8000000F
End Sub


Regards,
 
Upvote 0
Thx Colo;

i've already tried a very similar code like yours, but as i mentioned above, the button object may not need to lost focus to change the backcolor, just as in VB.

Thx again for your help,
 
Upvote 0
And one more...This is not a good way, but pls try it too.

<PRE><FONT color=red>Option Explicit</FONT>



<FONT color=red>Private <FONT color=red>Sub </FONT></FONT>CommandButton1_MouseMove(<FONT color=red>ByVal</FONT> Button <FONT color=red>As</FONT><FONT color=red> Integer</FONT>, _

<FONT color=red>ByVal</FONT> Shift <FONT color=red>As</FONT><FONT color=red> Integer</FONT>, _

<FONT color=red>ByVal</FONT> X <FONT color=red>As</FONT><FONT color=red> Single</FONT>, _

<FONT color=red>ByVal</FONT> Y <FONT color=red>As</FONT><FONT color=red> Single</FONT>)

<FONT color=red>Dim </FONT>i(0 <FONT color=red>To </FONT>1) <FONT color=red>As</FONT><FONT color=red> Single</FONT>

<FONT color=red>With </FONT>CommandButton1

i(0) = .Width / 4

i(1) = .Height / 4

<FONT color=red>If </FONT>X > i(0) And Y > i(1) And X < .Width - i(0) And Y < .Height - i(1) Then

.BackColor = &HFFFF&

<FONT color=red>Else</FONT>

.BackColor = &H8000000F

<FONT color=red>End If</FONT>

<FONT color=red>End With</FONT>

<FONT color=red>End Sub</FONT>
</PRE>
 
Upvote 0
But the problem is, the color is not static.
Woops, oh you are right...
Maybe it occur when excel can not be catched the MouseMove event.
I'll look into another way. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,212,938
Messages
6,110,771
Members
448,297
Latest member
cocolasticot50

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