none
Customize "Chart" pop-up menu in Excel RRS feed

  • Question

  • Hi,

    Currently I'm working on some Excel-Addins that will customize the "Chart" popup menu when you right mouse click on some live chart in Excel.

    The code we used is below:

    Microsoft.Office.Core.CommandBar chartCommandBar = null;

    for (int i = 1; i <= _theExcelApp.CommandBars.Count; ++i)
    {

        if (_theExcelApp.CommandBars[i].Name == "Object/Plot" && chartCommandBar == null)
        {
            chartCommandBar = _theExcelApp.CommandBars[i];
        }
    }

    if (chartCommandBar != null)
    {
        Microsoft.Office.Core.CommandBarPopup menuItem = (Microsoft.Office.Core.CommandBarPopup)chartCommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlPopup, missing, missing, missing, true);

        menuItem.Caption = menubarName;
        menuItem.BeginGroup = true;
            menuItem.Enabled = true;
            menuItem.Visible = true;
    }

     

    It works in Excel 2003 but doesn't work in Excel 2007. If I change "object/plot" to "cell", then it will work both in Excel 2003 and Excel 2007 for the "cell" pop-up menu. Does anyone know why this happens?

     

    Later on, I find some material like this:

    http://msdn.microsoft.com/en-us/library/gg469862.aspx%23odc_xl_ta_CustomExcelContextMenus_AddDynamicMenu

     

    I tried the new Ribbon Extensibilty technology in Office 2010. I find the solution provided still only works for "cell" pop-up menu but not for "chart" pop-up menu. Does microsoft make some limit that developer can't customize the "chart" pop-up menu?

     

    Hope to get your feedback. Thanks.

     

    Tuesday, April 12, 2011 2:23 AM

Answers

  • In 2010 with RibbonX it is working
     
    If you use the example from this artcle
     
    and use this in the RibbonX you see it will work
     
       <contextMenus>
          <contextMenu idMso="ContextMenuChartArea">
             <dynamicMenu id="MyDynamicMenu"
                label= "My Dynamic Menu" imageMso="HappyFace"
                getContent="GetContent" insertBeforeMso="Cut"/>
          </contextMenu>
       </contextMenus>
    </customUI>
     
     

    Regards Ron de Bruin
    http://www.rondebruin.nl/tips.htm


    "fmamstr" wrote in message news:c75ccd05-d92e-4136-97b6-d912ff3ca3a6...

    Hi,

    Currently I'm working on some Excel-Addins that will customize the "Chart" popup menu when you right mouse click on some live chart in Excel.

    The code we used is below:

    Microsoft.Office.Core.CommandBar chartCommandBar = null;

    for (int i = 1; i <= _theExcelApp.CommandBars.Count; ++i)
    {

        if (_theExcelApp.CommandBars[i].Name == "Object/Plot" && chartCommandBar == null)
        {
            chartCommandBar = _theExcelApp.CommandBars[i];
        }
    }

    if (chartCommandBar != null)
    {
        Microsoft.Office.Core.CommandBarPopup menuItem = (Microsoft.Office.Core.CommandBarPopup)chartCommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlPopup, missing, missing, missing, true);

        menuItem.Caption = menubarName;
        menuItem.BeginGroup = true;
            menuItem.Enabled = true;
            menuItem.Visible = true;
    }

     

    It works in Excel 2003 but doesn't work in Excel 2007. If I change "object/plot" to "cell", then it will work both in Excel 2003 and Excel 2007 for the "cell" pop-up menu. Does anyone know why this happens?

     

    Later on, I find some material like this:

    http://msdn.microsoft.com/en-us/library/gg469862.aspx%23odc_xl_ta_CustomExcelContextMenus_AddDynamicMenu

     

    I tried the new Ribbon Extensibilty technology in Office 2010. I find the solution provided still only works for "cell" pop-up menu but not for "chart" pop-up menu. Does microsoft make some limit that developer can't customize the "chart" pop-up menu?

     

    Hope to get your feedback. Thanks.

     

    • Marked as answer by Bruce Song Tuesday, April 26, 2011 1:58 AM
    Tuesday, April 12, 2011 3:41 PM

All replies

  • Hello fmamstr,

    Thanks for posting. By using the code above, I could reproduce this isue on my side. By researching a lot on this topic, I think that we could customize Chart context menu in Excel 2007. Here are two resources about same topic.

    Adding commands to the Excel 2007 Chart context menu:
    http://www.excelbanter.com/showthread.php?t=217595.

    Adding a context menu item for a chart in Excel?
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/e397c3f6-5495-47e6-ad4c-ac2413f69447/.

    If you have any concern on this post, just feel free to follow up. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 12, 2011 8:10 AM
  • As indicated in the links given by Bessie Zhao the popup dialogs that appear when you click chart items are not Commandbar popups like the "Cell" popup. IOW it is not possible to customize these as you can 2003 style commandbars. There is no simple workaround, even with your own customized popup which can work in some situations, other than add your controls to the Ribbon.

    Peter Thornton

    Tuesday, April 12, 2011 12:16 PM
    Moderator
  • In 2010 with RibbonX it is working
     
    If you use the example from this artcle
     
    and use this in the RibbonX you see it will work
     
       <contextMenus>
          <contextMenu idMso="ContextMenuChartArea">
             <dynamicMenu id="MyDynamicMenu"
                label= "My Dynamic Menu" imageMso="HappyFace"
                getContent="GetContent" insertBeforeMso="Cut"/>
          </contextMenu>
       </contextMenus>
    </customUI>
     
     

    Regards Ron de Bruin
    http://www.rondebruin.nl/tips.htm


    "fmamstr" wrote in message news:c75ccd05-d92e-4136-97b6-d912ff3ca3a6...

    Hi,

    Currently I'm working on some Excel-Addins that will customize the "Chart" popup menu when you right mouse click on some live chart in Excel.

    The code we used is below:

    Microsoft.Office.Core.CommandBar chartCommandBar = null;

    for (int i = 1; i <= _theExcelApp.CommandBars.Count; ++i)
    {

        if (_theExcelApp.CommandBars[i].Name == "Object/Plot" && chartCommandBar == null)
        {
            chartCommandBar = _theExcelApp.CommandBars[i];
        }
    }

    if (chartCommandBar != null)
    {
        Microsoft.Office.Core.CommandBarPopup menuItem = (Microsoft.Office.Core.CommandBarPopup)chartCommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlPopup, missing, missing, missing, true);

        menuItem.Caption = menubarName;
        menuItem.BeginGroup = true;
            menuItem.Enabled = true;
            menuItem.Visible = true;
    }

     

    It works in Excel 2003 but doesn't work in Excel 2007. If I change "object/plot" to "cell", then it will work both in Excel 2003 and Excel 2007 for the "cell" pop-up menu. Does anyone know why this happens?

     

    Later on, I find some material like this:

    http://msdn.microsoft.com/en-us/library/gg469862.aspx%23odc_xl_ta_CustomExcelContextMenus_AddDynamicMenu

     

    I tried the new Ribbon Extensibilty technology in Office 2010. I find the solution provided still only works for "cell" pop-up menu but not for "chart" pop-up menu. Does microsoft make some limit that developer can't customize the "chart" pop-up menu?

     

    Hope to get your feedback. Thanks.

     

    • Marked as answer by Bruce Song Tuesday, April 26, 2011 1:58 AM
    Tuesday, April 12, 2011 3:41 PM
  • Thank you Bessie. I have read the 2 links that you gave, but it seems the solution provided in the link doesn't work. Some replies in the link also said that it's not possible to customize the "Chart" context menu.
    Thursday, April 14, 2011 8:14 AM
  • Thanks Peter. So that means it's not easy(if not possible) to customize the "Chart" popup menu in Excel 2007, right?
    Thursday, April 14, 2011 8:15 AM
  • Many thanks! I have tried your code and it indeed works. It seems the popup menu is named "ContextMenuChartArea".
    Thursday, April 14, 2011 8:18 AM