1

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.

Community
  • 1
  • 1
Gav
  • 103
  • 1
  • 4
  • I'd be *very* surprised if you find a way of doing it in C# code - being able to do so requires isolation of each plugin into separate AppDomain which I don't think is there for Office plugins (you can check yourself by enumerating all AppDomains). – Alexei Levenkov Aug 27 '13 at 15:47

1 Answers1

2

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

Kiru
  • 3,489
  • 1
  • 25
  • 46
  • Hello, I have found out that you can even perform a "reload" of your Add-In: ` public void ReloadVstoAddIn() { var addIn = Application.COMAddIns.Item(""); addIn.Connect = false; //Unloads the Add-In addIn.Connect = true; //Triggers AddInBase.Startup event again } ` Regards, Jörg – jreichert Oct 30 '13 at 11:15
  • Sorry, that does only seem to work in the debugger. When I have tested my installed solution, my add-in stays unconnected, so it seems YOU CAN'T RELOAD you own add-In. Sorry, Jörg – jreichert Oct 31 '13 at 18:20