Mouse events in VBA

Darril

New Member
Joined
Nov 15, 2005
Messages
10
Hi all
I wish to write my own digitizing program where I paste a scanned graph into an Excel worksheet and then use mouse events like Mousmove and Mousedown get the coordinates of any point on the scanned image.

Please can somebody supply a simple example in VBA showing me how obtain the coordinates of the mouse cursor.

I refer to the following MSDN web page http://msdn.microsoft.com/library/d...vtMouseMove.asp

Many Thanks
Darril
 
The UserForm1 code below can be any code you need!
Its just a sample.

MyX = ActiveWindow.PointsToScreenPixelsX(X)

Select Case MyX
Case WM_MOUSEMOVE
UserForm1.Caption = "MouseMove!"

Case WM_LBUTTONDOWN
UserForm1.Caption = "Left MouseDown"

Case WM_LBUTTONUP
UserForm1.Caption = "Left MouseUp"

Case WM_LBUTTONDBLCLK
UserForm1.Caption = "Left DoubleClick"

Case WM_RBUTTONDOWN
UserForm1.Caption = "Right MouseDown"

Case WM_RBUTTONUP
UserForm1.Caption = "Right MouseUp"

Case WM_RBUTTONDBLCLK
UserForm1.Caption = "Right DoubleClick"
End Select
End Sub
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
i tried using the code posted in my worksheet selection change event, but it doesn't seem to work. the value for "X" is empty.

i am just trying to "check" for a pressed mouse button in the middle of the worksheet selection change event.
 
Upvote 0
In the sample "x" is the value returned by:

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
 
Upvote 0
i've been trying to use the code above (Public Const WM_LBUTTONDOWN = &H201 ) to find a way to trap mouse buttons clicks using the worksheet selection change event.
Please explain why you are trying to do this?

"to find a way to trap mouse buttons clicks using the worksheet selection change event"
 
Upvote 0
thanks for the replies, i completely missed the intial declaration! i guess that would help!

on certain cell ranges of my worksheet, i pop up a small user form that is populated with various lists of data from a different worksheet. the reason that i wanted to check for mouse clicks during the selection change event was for improved user navigation.

when i conditioned straight off of the selection change event, my popup form would popup when the user tried to index past one of the cell ranges. the user really only needs my user forms to popup when he changes cells using the mouse, not by using the key strokes.

if anyone is interested, reply back and i can post a couple screen shots and examples of the code.
 
Upvote 0

Forum statistics

Threads
1,225,071
Messages
6,182,685
Members
453,132
Latest member
nsnodgrass73

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