none
Show and hide ribbon groups using Customize Ribbon RRS feed

  • Question

  • Good day

    I've created a Microsoft Word Office 2010 VSTO add-in and am looking for a way to programatically remove a specific group from the ribbon when the add-in launches. At a later stage users should be able to re-add this group using Customize Ribbon functionality in Word:

    There is functionality to toggle the visibility of a group but if I do this attempts to make the group visible again using Customize Ribbon fail:

    groupName.Visible = false;


    • Edited by Denys W Thursday, September 6, 2012 12:30 PM
    Thursday, September 6, 2012 8:04 AM

Answers

  • Hi Denys

    The functionality in the UI is not made available to the programmer.

    And the reverse also holds true: the user cannot change the Visibilty setting of Ribbon controls your program has hidden. But you can provide a button with code to make it visible somewhere in the Ribbon. In this way the user can make it visible and add to the QAT or a Ribbon tab of his choice.

    If you really want to provide something similar to being able to add things to the Ribbon UI "on-the-fly" the only thing that comes to mind is to work with a Word template. Using the Open XML SDK you could create a Word template (*.dotx), add a customui XML part to it, then load the template as an Add-in (Application.Addins collection). That would integrate the template's custom Ribbon XML into the Word application. But it wouldn't link to any code at that point.

    Theoretically, you could then access the templates VBA components to create code in the template. It would probably even be possible to have it reference "COM visible" code in your add-in.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Denys W Friday, September 7, 2012 9:45 AM
    Friday, September 7, 2012 8:52 AM
    Moderator

All replies

  • Hi Denys

    By design, it's not possible to add/remove things from the Ribbon once it has been loaded. You certainly can dynamically define the XML for your add-in's Ribbon at the point it is loaded, but there's no way to put something in that's not originally in that XML.

    The usual way is to use the Visible or the Enabled attribute. I'm not sure what you mean by "if I do this attempts to make the group visible again using Customize Ribbon fail" as you don't offer any information about how it's failing.

    A workaround could be to put this Ribbon XML in a separate add-in, then your main add-in could load/unload this other add-in as required. It could be a COM add-in or a template add-in. If want the two add-ins to share Tabs or Groups, then you'd have to use Ribbon XML rather than the Ribbon Designer as the customizations would need to use the same namespace.


    Cindy Meister, VSTO/Word MVP

    Thursday, September 6, 2012 2:17 PM
    Moderator
  • Hello Cindy

    But if it's not possible how does the Customize Ribbon functionality add and remove groups?

    I want the same functionality as the "Add>>" and "<<Remove" buttons on Customize Ribbon.

    Or is this functionality exclusive to Words inner workings and not available to developers?

    "I'm not sure what you mean by "if I do this attempts to make the group visible again using Customize Ribbon fail" as you don't offer any information about how it's failing."

    This is quite simple, crteate an add in with a group.Set the visibility of the group to false and launch the add-in in Word. Now open Customize Ribbon and try add this group back, no matter what you do the group will not be shown



    • Edited by Denys W Friday, September 7, 2012 6:42 AM
    Friday, September 7, 2012 6:27 AM
  • Hi Denys

    The functionality in the UI is not made available to the programmer.

    And the reverse also holds true: the user cannot change the Visibilty setting of Ribbon controls your program has hidden. But you can provide a button with code to make it visible somewhere in the Ribbon. In this way the user can make it visible and add to the QAT or a Ribbon tab of his choice.

    If you really want to provide something similar to being able to add things to the Ribbon UI "on-the-fly" the only thing that comes to mind is to work with a Word template. Using the Open XML SDK you could create a Word template (*.dotx), add a customui XML part to it, then load the template as an Add-in (Application.Addins collection). That would integrate the template's custom Ribbon XML into the Word application. But it wouldn't link to any code at that point.

    Theoretically, you could then access the templates VBA components to create code in the template. It would probably even be possible to have it reference "COM visible" code in your add-in.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Denys W Friday, September 7, 2012 9:45 AM
    Friday, September 7, 2012 8:52 AM
    Moderator