none
Customizing RibbonX with C# RRS feed

  • Question

  • Hi together,

    I spent the last days searching for a solution, but all answers I found solved my problem only partially.

    I have an Excel 2010 document level customization and want to

    a) remove the original tabs from the ribbon

    b) add my own tab with my own buttons to the ribbon

    c) Exceute functionality when clicking the button

    Sounds simple and it seems to be as long as you work with VBA:

    a), b) enter the appropriate tags in customUi14.xml, no problem
    c) use the onAction Attribute and as long this refers to a VBA-Macro it seems to work.

    But I need the funtionality written in my C# custom code. So I tried
    a) enter the appropriate tags in customUi14.xml
    b) Add my own tab to the ribbon using C# code

    This works, saying the constructor/InitilaizeComponent() method is called. But it seems that the part from the customUi14.xml is run after my program code and overwrites my definition and so my own tab has gone, even if the customUi14.xml is present, but empty.

    So my question is:
    Is there a way to work with the built-in ribbon tabs from my Custom code
    or do I have the chance to run my functions (in the workbook context) using the entries in  customUi14.xml?

    All ideas are welcome!

    Thursday, May 19, 2011 5:05 PM

Answers

  • Hi Heinz

    I think the "disconnect" in your scenario is that, when you work with a VSTO document or Add-in the Ribbon XML should not be stored in a document. IOW you don't use a customUi4.xml part in the docx "package".

    Remove that from the document (make it a separate file on your disk).

    In the VSTO solution, ADD a Ribbon XML object to your project (right-click the project, choose "Add item", select Ribbon XML). Now copy the XML in customUi4.xml into the Ribbon XML "page" you added.

    At the same time Visual Studio creates the Ribbon XMl page it also adds a Ribbon class to your project. That's where the code for the callbacks go. You may also want to consult this link:

    http://msdn.microsoft.com/en-us/library/aa942866.aspx


    Cindy Meister, VSTO/Word MVP
    Friday, May 20, 2011 4:38 PM
    Moderator
  • Hi Cindy,

     

    thanks for your reply. I tried the Ribbon XML before, but it seems that I did something wrong, because it didn't work.

    Now I tried it again with a little demo project and it worked. After that I got it work in my real project as well.

    Thanks for directing me into the right direction.

    • Marked as answer by Kay Sommer Monday, May 23, 2011 8:43 AM
    Monday, May 23, 2011 7:57 AM

All replies

  • Hi Heinz

    I think the "disconnect" in your scenario is that, when you work with a VSTO document or Add-in the Ribbon XML should not be stored in a document. IOW you don't use a customUi4.xml part in the docx "package".

    Remove that from the document (make it a separate file on your disk).

    In the VSTO solution, ADD a Ribbon XML object to your project (right-click the project, choose "Add item", select Ribbon XML). Now copy the XML in customUi4.xml into the Ribbon XML "page" you added.

    At the same time Visual Studio creates the Ribbon XMl page it also adds a Ribbon class to your project. That's where the code for the callbacks go. You may also want to consult this link:

    http://msdn.microsoft.com/en-us/library/aa942866.aspx


    Cindy Meister, VSTO/Word MVP
    Friday, May 20, 2011 4:38 PM
    Moderator
  • Hi Cindy,

     

    thanks for your reply. I tried the Ribbon XML before, but it seems that I did something wrong, because it didn't work.

    Now I tried it again with a little demo project and it worked. After that I got it work in my real project as well.

    Thanks for directing me into the right direction.

    • Marked as answer by Kay Sommer Monday, May 23, 2011 8:43 AM
    Monday, May 23, 2011 7:57 AM