Is there a way to access a Ribbon (XML) at run time?
When working with Ribbon XML, I tried this but I couldn't access the Ribbon1 property from the Globals.Ribbons.. The property simple wasn't there..
However, I came up with another solution which basically had to do with a proper type cast.
In ThisAddIn.cs:
private Microsoft.Office.Core.IRibbonExtensibility ribbonObj;
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
ribbonObj = new Ribbon1(this);
return ribbonObj;
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Calling the public method TEST() in Ribbon1.cs
//MyNameSpace is the namespace used in your project ie., your project name
((MyNameSpace.Ribbon1)ribbonObj).TEST();
// Calling the public variable flag in Ribbon1.cs
((MyNameSpace.Ribbon1)ribbonObj).flag;
}
Globals.Ribbons is a VSTO designer feature, if you use RibbonXML then you don't have this feature. What the designer actually does under the covers is it will create ribbon xml for Office, then when office makes a callback, VSTO will raise the appropriate event handler for that context (document). Because you are using RibbonXML you are bypassing the VSTO Ribbon designer support entirely (I prefer it this way, it is faster and you have more control).
With ribbon XML you will have to register a onLoad callback for your label, Office will then pass you a IRibbonControl, which will be the label, and you have limited stuff you can do. If you wanted to change the text then off the top of my head you would have to register a getText callback, then invalidate that ribbon control, which will cause the getText callback to be reevaluated.
Having more info about what you actually want to achieve would be handy =) I have a feeling my VSTO contrib project will also make your life much easier, as it gives you many of the nice Ribbon Designer features when using ribbon xml. But let me know what it is you want to do, and I can give you more info about that.
Cheers, Jake
It depends on when you are trying to access Globals.ribbons.
As I recall, it won't be populated until very near the end of the start up phase of Word.
if you try and access it too early, there won't be any ribbons defined yet.