This project has moved. For the latest updates, please go here.

Registering Addin through NetOffice does not work

Apr 1, 2013 at 11:58 PM
Excel.Application excelApp = null;
        Excel.Workbook oWB = null;
        try
        {
            excelApp = new Excel.Application();
            excelApp.DisplayAlerts = false;
            excelApp.Visible = true;
            excelApp.AlertBeforeOverwriting = false;
            excelApp.Interactive = false;


            excelApp.DefaultFilePath = CurrentExecutionPath;

            oWB = (Excel.Workbook)(excelApp.Workbooks.Add(Missing.Value));


            //string filter = "*.xll";
            string[] Files = Directory.GetFiles(CurrentExecutionPath).Where(FileName =>
                                    FileName.EndsWith(".xll") || FileName.EndsWith(".XLL")).ToArray<string>();
            foreach (string File in Files)
            {

                bool Installed = excelApp.RegisterXLL(Path.GetFileName(File));
                //Excel.AddIn AddIn =  excelApp.AddIns2.Add(File);
                if (Installed)
                //if (AddIn != null)
                {

                    logger.Debug(File + " Registration Completed. ");
                }
                else
                {
                    logger.Debug(File + " Registration Failed ");
                }
            }

            foreach (Excel.AddIn AddIn in excelApp.AddIns2)
            {
                logger.Debug(string.Format("Add In Name : {0} , Location : {1}, File Name : {2}, Path : {3}",
                    AddIn.Application, AddIn.FullName, AddIn.Name, AddIn.Path));
            }
            oWB.Save();
        }
        catch (Exception ex)
        {
            logger.Debug(ex.ToString());
            MessageBox.Show(ex.ToString(), "Error");
            MessageBox.Show(ex.ToString(), "Error");
        }
        finally
        {
            //excelApp.Quit();
            oWB.Close();
            excelApp.Quit();
            oWB.Dispose();
            excelApp.Dispose();
        }

Above is my code for Registering AddIn; But they are not getting actually registered. I see they are being loaded when I call
bool Installed = excelApp.RegisterXLL(Path.GetFileName(File)); And if i put break point then I can see AddIn in bar but once program gets executed and then I reopen Excel I don't find them as "registered"...

Thanks
Apr 2, 2013 at 8:54 AM
Hello,

Did you register your Add-In in Microsoft Registry?
                // http://support.microsoft.com/kb/948461
                // register addin in Excel
                Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Office\Excel\Addins\<Addin name>");
                RegistryKey regKeyWord = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\Excel\Addins\<Addin name>", true);
                regKeyWord.SetValue("LoadBehavior", Convert.ToInt32(3));
                regKeyWord.SetValue("FriendlyName", "<Addin name>");
                regKeyWord.SetValue("Description", "<Description>");
                regKeyWord.Close();
Your Add-In can be done with .dll too instead of .xll which make the possibility of deploying it in Word/Excel/PowerPoint in same time.
Apr 4, 2013 at 1:27 PM
I can not understand how I set Addin cherep Windows Installer. Where in the Installer I prescribe the following code:
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Office\Excel\Addins\<Addin name>");
                RegistryKey regKeyWord = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\Excel\Addins\<Addin name>", true);
                regKeyWord.SetValue("LoadBehavior", Convert.ToInt32(3));
                regKeyWord.SetValue("FriendlyName", "<Addin name>");
                regKeyWord.SetValue("Description", "<Description>");
                regKeyWord.Close();
This is the only thing to do in the registry to Excel hooked up addin?
Apr 10, 2013 at 3:39 PM
I do not want to add Registry entries because I am deploying through ClickOnce and we do not have access to Registry. I am trying to deploy this without help of Administrator.

Let me know...

Thanks
Apr 16, 2013 at 3:19 PM
Edited Apr 16, 2013 at 3:20 PM
First of you need you a GUID for your application
[GuidAttribute("56F843AD-ECB8-45D6-9E33-C0928BD2FB03"), ProgId("<Add-In name>"), ComVisible(true)]
            try
            {
                // add codebase value
                Assembly thisAssembly = Assembly.GetAssembly(typeof(Addin));
                RegistryKey key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32\\1.0.0.0");
                key.SetValue("CodeBase", thisAssembly.CodeBase);
                key.Close();

                key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32");
                key.SetValue("CodeBase", thisAssembly.CodeBase);
                key.Close();

                // add bypass key
                // http://support.microsoft.com/kb/948461
                key = Registry.ClassesRoot.CreateSubKey("Interface\\{000C0601-0000-0000-C000-000000000046}");
                string defaultValue = key.GetValue("") as string;
                if (null == defaultValue)
                    key.SetValue("", "Office .NET Framework Lockback Bypass Key");
                key.Close();

                // register addin in PowerPoint
                Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Office\Excel\Addins\<Add In name>");
                RegistryKey regKeyWord = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\Excel\Addins\<Add In name>", true);
                regKeyWord.SetValue("LoadBehavior", Convert.ToInt32(3));
                regKeyWord.SetValue("FriendlyName", "<Add In name>");
                regKeyWord.SetValue("Description", "<description>");
                regKeyWord.Close();


            }
            catch (Exception ex)
            {
                string details = string.Format("{1}{1}Details:{1}{1}{0}", ex.Message, Environment.NewLine);
                MessageBox.Show("An error occured." + details, "Register Addin", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
This is a way to register it to your registry. Notice that the GUID must be unique, to avoid conflict between other Add-Ins.

Hope this might overcome your issue.

With VSTO, it generates at the end a Setup.exe, you don't need to use ClickOnce.
Apr 17, 2013 at 8:35 AM
Edited Apr 17, 2013 at 9:52 AM
Another thing you could do is,

In Microsoft Visual C# 2010 Express in Project Option-> Publish

You can create a ClickOnce there too which can check every xy day to update the software.

It also generates a setup.exe

Just created one and it works fine and updates also when a new version has been released, means it works with NetOffice too it's independent from it.

I open a window that allows me to Install/UnInstall my Add-In and it adds/removes my Add-In from registry.
Apr 29, 2013 at 2:44 PM
I do not want to add entries into Registry.