PDA

View Full Version : label right-click event



av8tordude
01-22-2011, 07:14 PM
I would like to run a code using the mouse right-click button. Unfortunately Labels do not allow this option. The only available click-event are "Click" & DblClick. Can some assist me in accomplish this task.

Thanks

Rob342
01-23-2011, 08:38 AM
Hi
Why are you using a label, these are for adding text to a sheet or form ?
Why not use a control button ?

Then you can code it by either:


Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)

' Put your code here or call a module and insert the code into the module.

End Sub


or

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
' Your code here
End Sub

I don't think there is a way via a label unless one of the experts knows different.

mikerickson
01-23-2011, 08:44 AM
You can use the MouseUp event
Private Sub Label1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
If Button = 2 Then
MsgBox "Right button clicked"
End If
End Sub

Rob342
01-24-2011, 01:02 PM
Hi Mike

Thanks for the info, i see the logic behind it, if you want to test for a value of the mouse click event.
rob342

av8tordude
01-24-2011, 02:42 PM
Thank you mike. It's exactly what I was looking for!:friends: