Add a custom ContextMenu to Excel 2010 using Office2010 FluentUI (xml ribbon code) RRS feed

  • General discussion

  • I need to add custom context menus to Excel.

    I have the following example but contextMenu only takes the idMso attribute which I understand to be only for identifying built in context menues, not for creating new custom context menues.

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns:TM4="TrsMan040XL2010" xmlns="" onLoad="Ribbon_Load">
        <contextMenu id ="ContextMenuText">
          <button idMso="FontDialog" visible="false" />
          <toggleButton id="MyToggle" label="My Toggle Button" />
          <button id="MyButton" label="My Button" insertBeforeMso="HyperlinkInsert" onAction="GetButtonID" />
          <menuSeparator id="MySeparator" />
          <menu id="MySubMenu" label="My Submenu" >
            <button id="MyButton2" label="Button on submenu" />
          <dynamicMenu id="MyDynamicMenu" label= "My Dynamic Menu" getContent="GetMyContent" />

    I can only find examples for adding to or customizing existing Excel Context menues.  When I try to change idMso to Name, i get the error: The 'name' attribute is not declared.  I assume this is because it's not part of the customUI schema.

    In the sample above I also have code for re-purposing some existing Excel menu items and a custom ribbon that work but I left them out for clarity.

    I have context menues in my project already that were added using Commandbars Example:

    Dim shrtMnu As Office.CommandBar = ThisApplication.CommandBars.Add(Name:="Tm3AddToRelease", Position:=Office.MsoBarPosition.msoBarPopup, Temporary:=True)

    However, these don't work when I migrate the job to Office 2013.

    How do I add a custom context menu along with my custum ribbon?


    Wednesday, June 11, 2014 5:01 PM

All replies

  • Hello John,

    Command bars were deprecated and not used any longer. You need to use the Fluent UI instead.

    The idMso attribute for specifying the built-in control IDs. You need to use the id attribute for your controls instead. You can read more about the XML markup in the following series of articles in MSDN:

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

    The Customizing Context Menus in Office 2010 article in MSDN describes context menus in depth.

    Wednesday, June 11, 2014 5:48 PM
  • I have read all the above articles prior to this

    I realize the commandbars are dead for 2013. That's why I'm here. 

    The above article 'Customize Context Menues in Office 2010' does not say how to create NEW context menus.  It's where I got the sample shown above.  The article only describes how to customize existing Microsoft Office context menus.

    I need to create new custom context menus, not edit their existing owns.


    John G.

    Wednesday, June 11, 2014 6:02 PM
  • John,

    There is no way to introduce your own context menus.The article states the following:

    Capabilities and Limitations of Context Menu Customization

    Context menu customization by using Ribbon extensibility offers you many options. Features include the following:

    • You can add built-in and custom controls (those types currently supported in the Ribbon menu control) to built-in context menus as follows:

      • Add controls at any position in the menu.

      • Add controls to any submenu.

      • Add custom submenus to built-in context menus.

    • Hide controls in built-in menus.

    • Add menu separator lines before or after any context menu item.

    • You can dynamically populate (when the submenu is expanded) custom submenus by using the dynamicMenu control.

    • You can also dynamically populate custom galleries that are displayed on the context menu.

    The following are options not available when customizing the context menu:

    • Adding control types that are currently not supported in context menus (such as combo boxes and inputs). This is discussed later in the article.

    • Re-assigning control labels and icons for built-in context menu controls.

    • Reordering controls within built-in context menus and submenus.

    • Dynamically populating built-in context menus.

    Wednesday, June 11, 2014 8:24 PM