Capturing pointer locations

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Has anyone had any success capturing pointer locations
within Excel? According to "MouseDown, MouseUp Events"
within Help, when you click on "Applies To", both events
should apply to a UserForm, so the following should allow
you to capture the pointer location of a UserForm:

Private Sub UserForm_MouseDown(Button, Shift, X, Y)
MsgBox X
MsgBox Y
End Sub

However, this does not work, and when you read Help
for "MouseDown" alone, it supposedly only applies to a
chart object.

I would like to capture the mouse location on a
spreadsheet and also a UserForm, so has anyone been able
to do this?

Regards
Paul
 
Paul,

Mousedown certainly works for me.

Where are you putting your code? Since it is a userform event, the code for it must go into the userform's codemodule and not a
standard module. All but the Msgbox lines should autogenerate when you select the userform's codemodule's MouseDown event.

Private Sub UserForm_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
MsgBox "X of the click: " & X
MsgBox "Y of the click: " & Y
End Sub

HTH,
Bernie
Excel MVP
 
I don't believe Bernie showed:

Private Sub UserForm_MouseDown(Button, Shift, X, Y)

Your button shift x and y are variants which doesn't match what is expected.

He showed:

Private Sub UserForm_MouseDown(ByVal Button As Integer, _
ByVal Shift As
Integer, _
ByVal X As
Single, _
ByVal Y As
Single)
MsgBox "X of the click: " & X
MsgBox "Y of the click: " & Y
End Sub

So use it as he posted it. You are not defining the event - it is already
defined. That is why it is always best to select the event from the
dropdowns and let excel put in the declaration.

Your code worked fine for me when I substituted Bernie's event code.

Regards,
Tom Ogilvy
 
Back
Top