CreateRibbonExtensibilityObject runs only once RRS feed

  • Question

  • Hi,

    I want Print option to show for one Word file 'Sample1.docx" and hide for another word file "Sample2.docx". For this, I have created word Addin and added Ribbon.

    I have achieved the functionality as mentioned above by changing GetCustomUI at rum time by setting value visible false/true of Print button but it is working only when if I open any one file (Sample1.docx/Sample2.docx) at the time, it does't not work if I open both file, means if "Sample1.docx" is open then close Sample1.docx before opening Sample2.docx otherwise if both are open, Print option in visible for Sample2.docx too which I don't want.

    Please help! If have any alternate solutions, let know


    Tuesday, June 25, 2019 11:09 AM

All replies

  • Hello,

    The GetCustomUI is called per window once. It loads the XML markup, either from an XML customization file or from XML markup embedded in the procedure, that customizes the Ribbon user interface.

    For Word, Excel, PowerPoint, and Access, there is only one ID for each application. Outlook uses ribbon extensibility to customize not only the ribbon in an inspector, but also the ribbon in an explorer, in various context menus, in contextual tabs on a ribbon, and in the Microsoft Office Backstage view. In each of these scenarios, the developer specifies the custom UI in an XML file that is loaded when Office calls GetCustomUI with a specific ribbon ID.

    public string GetCustomUI(string RibbonID) 
     StreamReader customUIReader = new System.IO.StreamReader("C:\\RibbonXSampleCS\\customUI.xml"); 
     string customUIData = customUIReader.ReadToEnd(); 
     return customUIData; 

    But what you really need is to implement a callback for the ribbon tab. Your callback name should be specified in the custom UI markup which is returned in the GetCustomUI function. 

    An add-in can use the IRibbonUI object to invalidate controls or menu items, and to update their content in the corresponding Microsoft Outlook user interface. The Invalidate and InvalidateControl methods of the IRibbonUI interface invalidate the cached values for the controls of the Ribbon user interface.

    For example, if an add-in writer implements the getVisible callback procedure for a ribbon tab, the function is called once, the visible state is checked. This process remains in place until the add-in signals that the cached value is invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. 

    Basically, when a document is opened you may give a signal to the ribbon UI to validate the visible state.

    Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:

    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)

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, June 25, 2019 12:48 PM