+ Reply to Thread
Results 1 to 17 of 17

Right Click Shape: Open Context Menu

  1. #1
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Right Click Shape: Open Context Menu

    I have created a Scrum Board by creating shapes that represent cards. I want to be able to right click a shape, and have a menu pop up. I already have custom context menus if the worksheet is right clicked, but I haven't figured out how to pop up a context menu if the user right clicks a shape.

    Any ideas? Thanks!

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,627

    Re: Right Click Shape: Open Context Menu

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Right Click Shape: Open Context Menu

    Assuming your context menu customization is via ribbon xml then try these alternative mso values.

    ContextMenuShape
    ContextMenuShapeConnector
    ContextMenuShapeFreeform
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    Hi Andy, not it isn't using the ribbon xml.

    I'm using this sort of code:
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Right Click Shape: Open Context Menu

    And do you use the BeforeRightClick event of the sheet to display the menu?

    If so you will not be able to use that approach for shapes.

    You might be able to use the old popup menu for shapes via the CommandBar object. But you may also find this is not used and ribbon xml will be the way forward.

    You will find a bunch of information on Ron de Bruin's page
    https://www.rondebruin.nl/win/s6/win001.htm

  6. #6
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    Hi Andy, yes I am using the BeforeRightClick event for worksheets, and MouseDown for Forms.

    Followup question: if I can't enable my own custom menu for shapes, can I disable context menus for shapes?

    I have looked everywhere for an answer, but it seems like it can't be done. I've tried Application.CommandBars("Shapes").Enabled = False which doesn't work.

    I have created a scrum board where shapes represent cards, so I don't want the right click Excel menu to spoil the illusion.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Right Click Shape: Open Context Menu

    Since xl2010 maybe 2013, not all the right click menus are of the CommandBar variety. So whilst the code may not fail items you add do not appear as what you are seeing is not the actual commandbar.

    As I said you can use the RibbonXML to add to contextMenus. See attached, right click shape to see new button at end of list.

    You will need to use ribbon xml such as this

    < customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    < contextMenus>
    < contextMenu idMso="ContextMenuShape">
    < menuSeparator id="MySeparator" />
    < button id="UML_Test" label="Test Me" onAction="UML_Test" />
    < /contextMenu>
    < /contextMenus>
    < /customUI>
    and the onAction VBA code in a standard code module,
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    Thank you Andy, I have not used XML ribbon code before, so I have to figure out how to use it. Thanks so much for this. I will report back.

  9. #9
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    Hi Andy, thanks. I see your code adds a custom menu option in the right click.

    The other question I have is: how do I remove all the other menu options and JUST HAVE the custom option? Thanks!!
    Last edited by superlative; 10-31-2019 at 11:47 AM.

  10. #10
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    I see that to disable the menus, I need to use the following code syntax:
    Please Login or Register  to view this content.
    and therefore the key is to identify all the idMso for each of the menu options in the shapes context menu. Q: how do I find this list? thanks!

  11. #11
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    I have found the idMso list, it's here:
    https://www.microsoft.com/en-us/down....aspx?id=36798

    I have also updated a modification to your file that makes all the idMso visible = false.

    You can see that most of them are hidden now.

    however - some of them are still visible. How do I remove the remaining ones? Thanks!!!! (I suspect it has to do with sub menus or something?)
    Attached Files Attached Files

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Right Click Shape: Open Context Menu

    They are not all button controls.

    In the workbook which contains the idMso values check what type of control each one is. There are toggles and menus

  13. #13
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    Hi Andy. I did a lot of research and nailed down a lot of the types, but there are some that don't seem to work. I found out that "Alternative Text" is a button, and yet I can't get rid of it. I can't seem to find the idMso for the ones that are still visible. For example "Link" - none seem to work. See updated file. Thanks!
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    Also, I found out I need to use ContextMenuObjectsGroup if I want to disable context menu on a group of shapes. However, if you right click on one of the sub-shapes, the Shapes context menu pops up.

    What is the syntax for modifying both the ContextMenuObjectsGroup and ContextMenuShape? Attached is a text file with the code, but it doesn't work.

    I have tried various combinations, but I can't figure it out. Thanks.
    Attached Files Attached Files
    Last edited by superlative; 10-31-2019 at 05:09 PM.

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Right Click Shape: Open Context Menu

    Yeah, that's one of the frustrations of the ribbon xml. The documentation gets worse each version. I have not been able to find a comprehensive list of all of the control ids.

  16. #16
    Forum Contributor
    Join Date
    10-10-2018
    Location
    Calgary, Canada
    MS-Off Ver
    Excel 2019 Windows 11
    Posts
    219

    Re: Right Click Shape: Open Context Menu

    Can anyone help me with my one problem now? What is the syntax to modify TWO context menus?

    I can only modify one. When I try to modify two, both stop working. I need to be able to modify both the Shapes Group and the Shapes context menu. See attached code 2 posts earlier. Thanks!

  17. #17
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Right Click Shape: Open Context Menu

    You need to give the second menuseperator control a different name if you want both contextmenus

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Adding to Right-Click Context Menu
    By FlossHoss in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2014, 10:02 AM
  2. [SOLVED] Add-In and Cell Context (Right-Click) Menu
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2014, 10:04 AM
  3. [SOLVED] Add-In & Cell Context (Right-Click) Menu
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-28-2014, 04:39 AM
  4. [SOLVED] How to remove commands like cut, copy, assign macro or ... from shape context menu
    By hmaleki in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-15-2013, 04:10 AM
  5. Screwed Up my Right Click Context Menu, Please Help
    By cpmame in forum Excel General
    Replies: 3
    Last Post: 03-12-2009, 12:13 PM
  6. Right-Click (Context Menu)
    By Kryptonix in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-25-2005, 11:05 AM
  7. [SOLVED] Right Click Context Menu
    By Guy Lapierre in forum Excel General
    Replies: 1
    Last Post: 03-30-2005, 07:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1