How to load/unload Word Add-in programatically?

我的未来我决定 提交于 2019-12-20 05:53:14

问题


I'd like to know how I can programatically load and unload a VSTO add-in in Word. I'm using Word 2007 and VS2010 with C#.

I thought I might have some luck with using the Microsoft.Office.Interop.Word.COMAddins and .Addins properties, but the .Addins property gives an empty list and COMAddins is a collection of opaque COM objects.

An alternative question suggests making the ribbon menu invisible, but I actually want to unload the add-in altogether.


回答1:


I had similar requirement and achieved it by little cheat.

I had a addin called AddinLauncher (with no ribbons) which will look for the user type and launch or closes the other addin.

This code was called during AddinLauncher Addin Startup event.

foreach (COMAddIn addin in Globals.ThisAddin.Application.COMAddins)
{
  if (**specify your own condition**)
    {
        addin.Connect = true;
    }                       
}

The following changes are required in your deployment

The Loadbehaviour for AddinLaucher addin is 3 and all the other addins are 0. More about Loadbehaviour here



来源:https://stackoverflow.com/questions/18469945/how-to-load-unload-word-add-in-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!