سؤال

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?

هل كانت مفيدة؟

المحلول 2

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;           

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top