简体   繁体   中英

Reloading an Excel Addin Programmatically

I have an excel plug in that has a number of features. I have a button on the ribbon titled "configuration settings" that allows the user to select whether or not to allow some options (whether to include a right click menu, or to display some buttons on my ribbon).

The only way that I know to define a right click menu or to design the ribbon is in the start up of the excel addin.

I have a config file that gets checked on load, but should the user change the configuration using my ribbon button, it has no effect until excel is re-opened or the user manually reloads the addin. Is there a way to do this programmatically?

Probably you could have two addins. (Addin1, Addin2)

First addin (Addin1) which doesnt have any ribbons but reads the configuration and then enables another addin (Addin2).

To enable the addins use the following piece of code.

foreach (COMAddIn addin in Application.COMAddIns)
{
   if (addin.ProgId.ToLower().Contains("addin2") && addin.Connect != true)
   {
      addin.Connect = true;
   }
}

I don't think you can reload an Add-In from inside the same Add-In. I tried it on my own - just unloading has worked for me.

But the buttons of a custom ribbon (eg named "Ribbon1") can be changed at runtime by accessing its properties via the "Globals" object:

Globals.Ribbons.Ribbon1.myRibbonButton.Visible = false;

Hope it helps, Jörg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM