View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
abcd[_2_] abcd[_2_] is offline
external usenet poster
 
Posts: 52
Default Before RightClick event change

Do try this


________INSIDE A MODULE:

Type POINTAPI
x As Long
y As Long
End Type

Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long


________INSIDE THE SHEET EVENTS:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

Dim point As POINTAPI
GetCursorPos point
[A1] = point.x
[A2] = Application.Left + 45
If (point.x < 45 + Application.Left) Then
Beep
Cancel = True
End If
End Sub



The idea: we check the position of the mouse
BUT this API function (GetCursorPos) gives the result in pixels (not
in point as Excel does) and also the result is given / screen (not the
excel window)

That's why i compare with Application.left
the constant 45 is supposed to be the width of the row-numbers

maybe there's a way to have the real value for it but i don't know
how. (remember if there's a lot of row, and the number needs 3 digits,
the the numbers will be wider)