Reputation: 752
I am trying to automate MS Word from my C# app and have a problem changing the ribbon UI. All samples I could find are using IRibbonExtensibility interface which is available from Addins only. Is it possible to do this using automation?
Upvotes: 1
Views: 1125
Reputation: 752
What I did was to build small ATL Addin which implements 2 Interfaces: IDTExtensibility2 and IRibbonExtensibility The customization XML is simply loaded from file.
Inside the C# code the coding is really simple:
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Office\Word\Addins\RibbonLoaderLib.RibbonLoader");
key.SetValue("LoadBehavior",2,RegistryValueKind.DWord);
key.SetValue("Description","Ribbon Loader Add-In",RegistryValueKind.String);
key.SetValue("FriendlyName","Ribbon Loader Add-In",RegistryValueKind.String);
wordApp_.COMAddIns.Item("RibbonLoaderLib.RibbonLoader").Connect = true;
Upvotes: 0
Reputation: 942408
using IRibbonExtensibility interface which is available from Addins only
Which means that it won't work through Automation, the interface is not exposed in the out-of-process type library. You'll have to use VSTO to write an add-in, use the C# + Office + Word 2007 Add-in project template to get started.
Upvotes: 2