问题
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