Re: Reloading the addin while Excel is open

776 views
Skip to first unread message

Govert van Drimmelen

unread,
Feb 15, 2013, 8:37:17 AM2/15/13
to Excel-DNA
Hi Michael,

you might try something like:
XlCall.Excel(XlCall.xlfRegister, @"path\to\addin.xll");

this should reload the add-in and re-register the functions.

However, I'm not sure whether you'd be able to update 'yourself' this
way.
Also, the .xll will always be locked while it is loaded, as I guess
you've noticed. One way to update it is to have multiple
subdirectories for different versions, and then update the .dna file
to point to the right subdirectory.

-Govert


On Feb 14, 3:19 pm, Michel Rasschaert <michel.rasscha...@gmail.com>
wrote:
> Hello group,
>
> Is there a way to reload the addin while Excel is running ?
>
> The idea is to do seamless updates to the addin (we can already replace the
> files with the help of the shadow copying support).
>
> Thanks for your help and this great framework.
>
> Michel

Govert van Drimmelen

unread,
Mar 26, 2013, 2:07:24 AM3/26/13
to Excel-DNA
Hi,

Best plan is to have a 'host' add-in that loads and unloads the other
add-ins. I paste some code for the 'host' below.

-Govert


<DnaLibrary Name="AddInHost" Language="C#" RuntimeVersion="v4.0">
<Reference Name="System.Windows.Forms" />
<![CDATA[
using System;
using System.Windows.Forms;
using ExcelDna.Integration;

public class MyMacros
{

public static object registerId;

[ExcelCommand(MenuName="AddinHost", MenuText="Load Addin")]
public static void LoadAddin()
{
XlCall.XlReturn result = XlCall.TryExcel(XlCall.xlfRegister,
out registerId, @"C:\Work\ExcelDna\Samples\MetaAddin\AddIn.xll");
}

[ExcelCommand(MenuName="AddinHost", MenuText="Unload Addin")]
public static void UnloadAddin()
{
MessageBox.Show("About to call xlAutoRemove.");

string theName = @"C:\Work\ExcelDna\Samples\MetaAddin
\AddIn.xll";
object removeId = XlCall.Excel(XlCall.xlfRegister, theName,
"xlAutoRemove", "I" , ExcelMissing.Value, ExcelMissing.Value, 2);
object removeResult = XlCall.Excel(XlCall.xlfCall, removeId);
object removeUnregister = XlCall.Excel(XlCall.xlfUnregister,
removeId);

object success = XlCall.Excel(XlCall.xlfUnregister,
registerId);
MessageBox.Show("Result of Unregister: " +
success.ToString() );
}
}
public static class MyFunctions
{
public static string AddinHostTestFunction()
{
return "Hello from the add-in host!";
}

[ExcelCommand(MenuName="AddinHost", MenuText="Say Hello!")]
public static void AddIn()
{
MessageBox.Show("Hello from the add-in host!");
}
}
]]>
</DnaLibrary>
Reply all
Reply to author
Forward
Message has been deleted
0 new messages