Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic update of (Excel-DNA) XLL with Excel opened

I am developing an Excel XLL Add-In using Excel-DNA and C#. The Add-In is called MyAddIn.xll. The Add-In has been saved to the users local machines, and it has been installed/added to Excel by the following procedure:

Excel Options --> Add-Ins --> Manage Excel Add-Ins --> and then adding MyAddIn.xll.

I now want to push out an update of MyAddIn.xll to all my users. I am using a deploy tool such as Salt. However, it seems like this require Excel to be closed on the users machines.

Is there a way that I can push the new xll to the users machines, when they have Excel opened, and letting the change take place when they restart Excel?

Thanks!

like image 565
Samuel Avatar asked May 21 '15 10:05

Samuel


1 Answers

The .xll file will always be locked by Excel, so you can't update that file while the add-in is loaded. You might be able to structure your add-in so that the .xll does not change with the updates, but the .dll file(s) that you use do change.

There are two approaches the Excel-DNA supports for doing this:

  1. The .dna files can redirect to subdirectories, and your root .dna file can be updated while the add-in is loaded. So you might have:

    • \AddInRoot\MyAddIn.xll
    • \AddInRoot\MyAddIn.dna
    • \AddInRoot\Version1\MyAddInImpl.dna
    • \AddInRoot\Version1\MyAddInImpl.dll
    • \AddInRoot\Version2\MyAddInImpl.dna
    • \AddInRoot\Version2\MyAddInImpl.dll

    And in MyAddIn.dna you have <DnaLibrary ...> <ExternalLibrary Path="Version1\MyAddInImpl.dna" /> </DnaLibrary>

    The while the add-in is loaded, you can replace MyAddIn.dna with a new version that refers to the new Version2 directory.

  2. Excel-DNA supports loading the .dll library files without locking the .dll. So you can have: <DnaLibrary ...> <ExternalLibrary Path="MyFunctions.dll" LoadFromBytes="true" /> </DnaLibrary>

    Then you will be able to replace MyFunctions.dll even while the add-in is running.

In both cases you need not re-open Excel to load the new version, you can just File->Open the .xll file and it will reload (or call xlfRegister or Application.RegisterXLL from code).

like image 109
Govert Avatar answered Sep 19 '22 21:09

Govert