ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Before RightClick event change (https://www.excelbanter.com/excel-programming/333231-before-rightclick-event-change.html)

broogle

Before RightClick event change
 
Hi, I am trying to use "Before_RightClick" event change in my code,
but, I just want to make this event being triggered only if the user do
the rightclick on the row(s) (the left handside number of the
sprdsheet) not anywhere else in the workbook area.
How can I identify this?

Thanks


abcd[_2_]

Before RightClick event change
 
In fact, the event will always be called for every cell
you must check wich row is the caller once the macro is lauched.

For this purpose you may use the Target given in argument
example:

if not( intersect(Target,Rows(12)) is Nothing ) then
'.... the code
end if

Dave Peterson[_5_]

Before RightClick event change
 
Maybe you could check to see if the selection is a whole row(s).

Option Explicit
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address < Target.EntireRow.Address Then
Cancel = True
Exit Sub
End If

'do your stuff
MsgBox Target.Address

End Sub

broogle wrote:

Hi, I am trying to use "Before_RightClick" event change in my code,
but, I just want to make this event being triggered only if the user do
the rightclick on the row(s) (the left handside number of the
sprdsheet) not anywhere else in the workbook area.
How can I identify this?

Thanks


--

Dave Peterson

Vasant Nanavati

Before RightClick event change
 
I don't think that was the OP's question.

Perhaps:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
If Target.Address = Target.EntireRow.Address Then
Cancel = True
MsgBox "Aha!"
End If
End Sub

--

Vasant


"abcd" wrote in message
...
In fact, the event will always be called for every cell
you must check wich row is the caller once the macro is lauched.

For this purpose you may use the Target given in argument
example:

if not( intersect(Target,Rows(12)) is Nothing ) then
'.... the code
end if




abcd[_2_]

Before RightClick event change
 
you say this because of the
"on the left handside number of the sprdsheet"

you are right and wrong at the same time: because in your case the macro
will open anywhere in the row since the entire row has been selected first.
if you select the row (left clic on the number) then right clic
anywhere in the row, then YOUR macro is executed and shows the "Aha"
message... This is not really a solution neither.

I'm not sure there's a (simple) way to be sure the clic was on the left.

This mean Broogle can have a macro lauched only when the clic is in
the row, (with my code wiht no need to select first the entire row, with
yours, need to select the entire row but may be before)

My and neither your code guaranty only the "left number in the margin"
clic asked !

I do not know the way to really check the position of the mouse when
the clic occurs. But if there's a solution, he needs to look at the
mouse coordinates and check these are at the left of the left cell of
this row (after having my or your way of selection, one more test).

Vasant Nanavati

Before RightClick event change
 
Good point, and it's probably not worth the effort.

--

Vasant


"abcd" wrote in message
...
you say this because of the
"on the left handside number of the sprdsheet"

you are right and wrong at the same time: because in your case the macro
will open anywhere in the row since the entire row has been selected
first.
if you select the row (left clic on the number) then right clic anywhere
in the row, then YOUR macro is executed and shows the "Aha" message...
This is not really a solution neither.

I'm not sure there's a (simple) way to be sure the clic was on the left.

This mean Broogle can have a macro lauched only when the clic is in the
row, (with my code wiht no need to select first the entire row, with
yours, need to select the entire row but may be before)

My and neither your code guaranty only the "left number in the margin"
clic asked !

I do not know the way to really check the position of the mouse when the
clic occurs. But if there's a solution, he needs to look at the mouse
coordinates and check these are at the left of the left cell of this row
(after having my or your way of selection, one more test).




abcd[_2_]

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)


All times are GMT +1. The time now is 06:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com