Rightclick Menu in VBA Userform

hicksi

Board Regular
Joined
Mar 5, 2012
Messages
203
I have a CommandButton defined that creates a report.
I want to do two different (related) things:
1: Define shift-keys so:
  • If no shift-key, the report is shown in preview
  • If the user Shift-clicks. the report is sent directly to the printer
  • If the user Ctrl-Clicks, the report is automatically saved to disk
  • Double-click, a new form is displayed that allows them to filter the data being reported
2: Provide a right-click that displays a popup that gives menu-access to those (and displays the shortcut keysets)

Some of it I have working (key-combinations), and I have some templates done to get the popup.

BUT...
I have seen some posts about using the CommandBars object which seems to be cleverer and doesn't need to access and intimately control low-level functions.
Anybody know of how to make all this work, and whether it is possible/probable to do this?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
The shift-key template is in
 
Upvote 0
Assign an accelerator key to the menu item by using use an ampersand (&) in the menu caption before the accelerator key.
For example:
VBA Code:
With .Controls.Add(Type:=msoControlButton)
  .Caption = "&Button 1"


Also, have a look at the msoControlButton ShortcutText Property :
For example:
VBA Code:
With .Controls.Add(Type:=msoControlButton)
  .Caption = "Button 1"
  .ShortcutText = "Alt+B"
 
Upvote 0
{{{hugs}}} That is all so simple when you know how.
Thank You
I should have mentioned that the ampersand (&) accelerator won't work with the Alt or Ctrl keys .. It only works with Shift key .

I guess you wil need more vba coding if you want to evoke the menu onaction macro via the Alt + Key combination.
 
Upvote 0
But I'll reinstate it if you can also tell me how to put a line to separate segments of the popup
Like
1601280850240.png
 
Upvote 0
But I'll reinstate it if you can also tell me how to put a line to separate segments of the popup
Like
View attachment 23179

Use the BeginGroup Property:
VBA Code:
With .Controls.Add(Type:=msoControlButton)
    .BeginGroup = True
    .Caption = "Button 2"

I have experimented a bit with this and have found that pressing the ALT key while a popup menu is on display unloads (closes) the entire popup menu... Try that and see. (In fact, the Alt key closes all drop menus- not just context menus.)

I think, the only workaround that may work for setting the shortcut keys combo (Alt + Key ) is via the RegisterHotKey API or a by setting a keyboard hook.

I'll further experiment with this and will post if anything comes up.
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,559
Members
448,970
Latest member
kennimack

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