View Full Version : Right mouse click on user form
ukdane
01-14-2009, 03:52 AM
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
Jan Karel Pieterse
01-14-2009, 04:20 AM
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.
Bob Phillips
01-14-2009, 06:50 AM
Something like this
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.