문제

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