Context menu

C

cmpcwil2

Hi,
Is it possible to have a right click menu display when you right clic
on an object such as a VB combobox? I can get the menu to appear whe
right clicking on a cell but not on a combobox.

Dim NewControl As CommandBarControl
Set NewControl = Application.CommandBars("cell").Controls.Add
With NewControl
.Caption = "Clear Combo"
.OnAction = "Clear"
.BeginGroup = True
End With

Many thank
 
A

Ardus Petus

Private Sub ComboBox1_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)

Upon right-click, you can show your own popup menu

HTH
 
A

Ardus Petus

This will show your customized "cell" menu upon right-clicking on the combo.

Private Sub ComboBox1_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 Then
CommandBars("cell").ShowPopup
End If
End Sub

HTH
 
C

cmpcwil2

I have a context menu to appear upon a right click of the mouse whilst
on a combo box. However the menu appears twice once when you right
click and then again upon selection of a menu item, I have implemented
the code above in a class module so not sure if this is the problem,
here is my code:

set up menu in module:

Dim NewControl As CommandBarControl
Set NewControl = Application.CommandBars("cell").Controls.Add
With NewControl
..Caption = "Clear Combo"
..BeginGroup = True
End With

call the menu from class module depending upon which combo box has
focus:
Sub ComboGroup_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)

If Button = 2 Then
CommandBars("cell").ShowPopup
ComboGroup.Text = ""
ComboGroup.clear


End If
End Sub

Can anyone help me on this? thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top