Consulting

Results 1 to 5 of 5

Thread: label right-click event

  1. #1

    label right-click event

    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

  2. #2
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    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:

    [vba]
    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[/vba]


    or

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

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

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You can use the MouseUp event
    [VBA]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[/VBA]

  4. #4
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    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

  5. #5
    Thank you mike. It's exactly what I was looking for!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •