How to unload an XLL programmatically in VBA

Mar 21, 2015 at 5:24 PM

I'm starting to use Excel-DNA and I need your help for the follwoing issue.

I wonder if there is a way to programatically unload an XLL addin in order to release the DLL.
I need to release the DLL in order to recompile it when I'm debugging.

1st Solution:
I imported the addin in Excel by using the addin manager. Then, from a VBA macro, I'm able to load and unload the addin by using the "Application.AddIns("Name of Addin").Installed" property.
It works, but this solution is not so clean since the I have to import the addin in Excel by using the addin manager.

2nd Solution:
Using "Application.RegisterXLL" and "UNREGISTER" Excel 4 macro to register and unregister the XLL.
Registering and unregistering works, but when the addin is unregistered, the DLL is not released and cannot be overwritten.

My question is: Do you have a solution to unload an addin and releasing the corresponding DLL in order to be able to overwrite it ?

Maybe you have a trick in order to debug the addin you are developping without having to save and close the Excel sheet in order to recompile it.
(I know that it's possible to configure Visual Studio to launch Excel for debugging, but this feature is not available in the express version).

Mar 21, 2015 at 5:32 PM
Easiest is to modify the .dna file, and set the LoadFromBytes="true" flag:
<DnaLibrary Name="My Add-In" RuntimeVersion="v4.0">
  <ExternalLibrary Path="MyLib.dll" LoadFromBytes="true" Pack="true" />
This will load the .dll without locking the file. So you can just recompile and reload the add-in to refresh.

There are some ways to get debugging to work with the Express version.
But there is now a "Community Edition" of Visual Studio, which is free for most users, and is essentially the Pro version. See

Marked as answer by SigmaPic on 3/21/2015 at 10:36 AM
Mar 21, 2015 at 5:38 PM
Thank you for your very fast answer (amazing).
It works perfectly.