Automatic update of (Excel-DNA) XLL with Excel opened
Asked Answered
A

1

8

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!

Auberta answered 21/5, 2015 at 10:21 Comment(0)
M
11

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).

Macadamia answered 21/5, 2015 at 15:7 Comment(2)
Hi Govert, I just tried doing solution 2 above. It works for the MyAddIn.dll that is the C# project where all Excel functions are exposed (and where the dna file is located). However, it does not work for other dll's that are referenced by this project (for example ExcelDna.Integration).Auberta
Ah yes - I had forgotten about that option. You never need ExcelDna.Integration.dll in your output directory, and it might do some harm. The right one is already packed inside the .xll file. Just set the Reference to ExcelDna.Integration to "Copy Local=false" in your project.Macadamia

© 2022 - 2024 — McMap. All rights reserved.