Enabling excel add-in programmatically

2

Sometimes my excel Addin gets disabled if it ends up being in the disabled COM Addins I can enable it with the following code. However if it ends up in disabled items I can't enable it using this code. Is there a way I can enable a disabled item. Not sure if I could do it using regedit or not.

I get a COM exception {"Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))"}

    xl.Application myApp = new xl.Application();

    foreach (COMAddIn currentAddIn in myApp.COMAddIns)
    {
        if (currentAddIn.Description == "Create Excel AddIn" && !currentAddIn.Connect)
        {
            try
            {


                currentAddIn.Connect = true;
            }
            catch (Exception)
            {
                CommonMethods.ExceptionHandler("Create tab couldn't be enabled", new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod());
            }


            break;
        }

    }


    return false;
}
c#
asked on Stack Overflow Jun 29, 2017 by Craig Gallagher

2 Answers

2

This was the best and most efficient solution.

using (RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\Excel\Addins\Create.ExcelAddIn", true))
{
    if (myKey != null)
    {
        myKey.SetValue("LoadBehavior", "3", RegistryValueKind.DWord);
        myKey.Close();
    }
}
answered on Stack Overflow Jun 29, 2017 by Craig Gallagher • edited Apr 30, 2020 by JohnLBevan
-1

The only way that I know of for completely disabled add-ins is to delete the registry key in the location below, but it can't be done while Excel is open (change 16.0 to the Office version):

HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Word\Resiliency\DisabledItems\
answered on Stack Overflow Jun 29, 2017 by Slai

User contributions licensed under CC BY-SA 3.0