Consulting

Results 1 to 3 of 3

Thread: Right mouse click on user form

  1. #1
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location

    Right mouse click on user form

    Excel 2003.
    It doesn't seem to be possible to use a right-click function on my user form.

    Is it at all possible?
    Is it possible to create your own "rightclick" menu?

    Cheers

  2. #2
    The userform has a mouseup event which you can use to check if it has been right-clicked. Note that this event only fires if the user clicks outside of a control. So basically you'd have to add a mouseup event to each control you want a rightclick action for as well. The Button argument tells you what mousebutton was used.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Something like this

    [vba]

    Private Sub Userform_Initialize()
    'Remove any old instance of MyPopUp
    On Error Resume Next
    CommandBars("FilePopUp").Delete
    On Error GoTo 0

    With CommandBars.Add(Name:="FilePopUp", Position:=msoBarPopup)
    With .Controls.Add(Type:=msoControlButton)
    .OnAction = "ShowDataForm"
    .Caption = "Data Form"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .OnAction = "procExit"
    .Caption = "Exit"
    End With
    End With
    End Sub


    Private Sub UserForm_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, _
    ByVal X As Single, ByVal Y As Single)
    If Button = xlSecondaryButton Then
    Application.CommandBars("FilePopUp").ShowPopup
    End If
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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