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
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
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.
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