locked
Why these do not work? RRS feed

  • Question

  • Hi there ..

    Case 1
    ======
    I created word add-in & added Ribbon(XML). Now in my code, Ribbon_Load() event  I'm trying to disable the office menu's New command through the word object model:

    public void Ribbon_Load(Office.IRibbonUI ribbonUI)
    {
       this.ribbon = ribbonUI;
       Globals.ThisAddIn.Application.CommandBars[1].Controls[1].Enabled = true; //disable the New Command
    }

    This does not throw any error but does not disable the New Command. I want to do this thru code instead of Ribbon.XML file. Is this possble?

    Case 2
    =====

    In Word VBA macro Window, I have written an event thats get trigged on click of office word button. In this event I'm trying to disable the office button New command. 

    Sub onButtonClick(control As IRibbonControl)
        Application.ActiveDocument.CommandBars(1).Controls(1).Enabled = False
    End Sub

    This event gets trigged but does not disable the New Command of office menu. Why?


    Thanks,
    Sanban

    Tuesday, December 9, 2008 5:48 PM

Answers

  • You cannot control the Ribbon UI through the CommandBars part of the object model. The RibbonUI can be controlled only through the same "container" that loads a set of Ribbon customizations (in this case, your add-in). This is by design.

    To change the enabled state of visibility of Ribbon controls in your Ribbon customization you must set the getVisible and getEnabled attributes for the Ribbon controls to callback methods. Then the Ribbon as a whole, or the individual controls, must be invalidated in order to have these attributes re-evaluated using the InvalidateControl or the Invalidate method, respectively.

    You might find it helpful to work through the 3-part article about customizing the Ribbon, which you'll find on the MSDN site for the "Office Fluent User Interface".    

    If you were using the Ribbon Designer instead of Ribbon XML, you would need to have methods that set the .Visible and .Enabled properties of the controls.

    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Sanban Thursday, December 11, 2008 5:55 PM
    Wednesday, December 10, 2008 7:25 AM

All replies

  • You cannot control the Ribbon UI through the CommandBars part of the object model. The RibbonUI can be controlled only through the same "container" that loads a set of Ribbon customizations (in this case, your add-in). This is by design.

    To change the enabled state of visibility of Ribbon controls in your Ribbon customization you must set the getVisible and getEnabled attributes for the Ribbon controls to callback methods. Then the Ribbon as a whole, or the individual controls, must be invalidated in order to have these attributes re-evaluated using the InvalidateControl or the Invalidate method, respectively.

    You might find it helpful to work through the 3-part article about customizing the Ribbon, which you'll find on the MSDN site for the "Office Fluent User Interface".    

    If you were using the Ribbon Designer instead of Ribbon XML, you would need to have methods that set the .Visible and .Enabled properties of the controls.

    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Sanban Thursday, December 11, 2008 5:55 PM
    Wednesday, December 10, 2008 7:25 AM
  • Thanks for your input ..I got this worked ...I referred this article in MSDN http://msdn.microsoft.com/hi-in/library/bb421511(en-us).aspx.

    I have an another question, in this article we toggle(hide & show) the view tab on click of a button. This worked fine. Now I want to expose this functionality through an automation object so that VB/VBA user can hide and show the view tab though programming.[Here Andrew has mentioned how to expose an object in VSTO Add-in(http://blogs.msdn.com/andreww/archive/2007/01/15/vsto-add-ins-comaddins-and-requestcomaddinautomationservice.aspx)]. But I'm not sure when & where should I call the Ribbon.Invalidator() funtion to invalidate the ribbon.

    Thanks !!
    • Edited by Sanban Wednesday, December 10, 2008 10:25 AM cnaged text
    Wednesday, December 10, 2008 10:23 AM
  • Hi Htere..

     In MSDN there is an article on "Changing Office Fluent UI Properties Like Command Bars at Run Time"(http://msdn.microsoft.com/en-us/library/bb194905.aspx#Office2007TaskPanesRibbonVBA_ChangingRibbonUIProperties).

    But its not explained properly and difficult to understand what to do & how. Has anybody tried to do the same and got it worked?

    Thanks in advance !!!

    • Merged by Mary Lee - MSFT Friday, December 12, 2008 6:31 PM related questions
    Wednesday, December 10, 2008 11:27 AM
  • What the MSDN article describes in the section you mention is essentially what the VSTO technology is already doing: wrapping the Ribbon XML so that you can use tabs, groups and controls you define for your custom Ribbon as "objects".

    If you want to use VSTO (and that's what's supported in this forum), then the article is of interest, but you don't need to use or understand what is written there.

    If you create a VSTO add-in, using VSTO 2008 and the Ribbon Designer, then all you need to do is set the .Visible and .Enabled properties of the Ribbon controls in the Ribbon class that is created for you. This article describes how VSTO has "wrapped" the Ribbon in a similar way as described in the article you cite.

    If you're not using VSTO, then we cannot help you here, in the VSTO forum. In that case, you need to go to one of the office.developer newsgroups, or find a site that specializes in the Ribbon.
    Cindy Meister, VSTO/Word MVP
    Thursday, December 11, 2008 5:41 PM
  • Hey ...

    It worked for me...I declared a static Ribbon variable & and a static get function in ThisAddIn class and access the same in my exposed class. Now my VB/VBA user can access my automation exposed class to programatically change the ribbon interface.

    Thanks a lot Cindy for your help !!!

     

    Thursday, December 11, 2008 5:55 PM