Hey Alex and Govert
I have a similar situation where I needed the addin to only work in a specific workbook.
In my case I am making template workbooks(xltm) for specific reports, where the user can enter in criteria using a form or range and the data is returned to the workbook. My first attempt I followed the normal steps, but the addin was available in every workbook. Unfortunately, some of the data/buttons/options cannot be shared with users outside of a department. At this point I almost thought Exceldna would not work for me.
Then I thought about my existing VBA app in which I added my own custom Ribbon using the Custom UI Editor app and I wondered if I could wire up Exceldna
to those the ribbons callbacks in the VBA script in that specific workbook. It worked!
1. Create a normal Exceldna addin in C# and get everything working.
2. Create an xltm file (or any xl file type) and add a module with ribbon callbacks that match the names of the commands--
Sub btnRefresh(Control As IRibbonControl)
Application.Run(''RefreshCommand")
End Sub
4. Comment out the Exceldna RibbonUI xml portion in the C# solution.
5. Make sure to pack all extra dll files and build the solution.
6. Install the packed xll file and run the xltm file...
The addin commands will only be available for the buttons and callbacks in your custom ribbon in that specific workbook.
In my case I rename the dna files specific to the report xltm file so I can install multiple addins for users that handle multiple files... otherwise they only need the specific addin for that specific file.
Notes:
- Have not used this method with UDFs.
- Develop the addin like a normal excel dna addin first and then convert it over, if you dont, you wont have the debugging messages to help you.
In my case I have a master addin that is only available to me. I develop with that, and then create a seperate solution for the specific report addin and copy over what i need. This lets me have the debugging and allows me to continue development without affecting the end user. The addin xll file is stored in the same folder as the report and when the user installs they do not copy to their PC addin folder. This allows me to switch the xll file when I am ready to release a new version to them without reinstalling everything... you can also switch the xltm files if needed as well.
I am sure this is probably a convoluted process, but it works for me.
To date I have not had any issues with this setup and the exceldna file works just fine in a hybrid style.
However, please let me know your thoughts, especially if I have overlooked something critical.
Hopefully my fingers kept up with my brain and this makes sense