Identify right click on my toolbar button

gonen

New Member
Joined
Mar 6, 2011
Messages
9
Hello

I have an xla file with private toolbar and few buttons.

When I click on a button, the assigned macro starts to run.

I am trying to assign two different processes to a button: one for click, and the other for right-click.

my question is:
is it possible assign two macros to a toolbar buttons. one for click and second for right-click.

or

is it possible to assign a macro to the click, and to open a customized toolbar on right click of the same button ?



currently the button is assigned a macro using this code:
Code:
            With .Controls.add(Type:=msoControlButton)
                .OnAction = "'" & ThisWorkbook.Name & "'!" & macroname
                .Style = msoButtonIconAndCaption
                .FaceId = iconnum(iCtr)
                .TooltipText = tt
            End With
thanks for help
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I don't think you can do a right click on a toolbar. In Excel 2003 it brings up the select toolbar menu. I had a similar desire in one of my programs, so I ended up using a control+click and a shift+click for 2 other functions from a single button. You could also use a combination of the two to get a 4th function. Would this work for you?
 
Upvote 0
Put this in your toolbar button event. I also added an explanation to the toolbar button tip to show what the combinations did.

Code:
    'Control but not Shift
    If CBool(GetKeyState(vbKeyControl) And &HFF80) And Not CBool(GetKeyState(vbKeyShift) And &HFF80) Then
    
    'Shift but not Control
    ElseIf CBool(GetKeyState(vbKeyShift) And &HFF80) And Not CBool(GetKeyState(vbKeyControl) And &HFF80) Then
    
    'Shift and Control
    ElseIf CBool(GetKeyState(vbKeyShift) And &HFF80) And CBool(GetKeyState(vbKeyControl) And &HFF80) Then
    
    'Not Shift and not Control
    Else
    
    End If
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top