Posted by ToM on 1. April 2009 under UDF |
There are two ways to register an User Defined Formula in Excel:
- Register it through the registry by adding the necessary keys, or
- Load it programatically during runtime
Registering during setup using the registry
To register the UDF during the setup process, you need to add a custom action to your setup project and add a key to
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Options
The name of the key is OPEN[ID], while ID is an incrementing number. You therefore need to find an unused number and add the respective key. For example, if you have keys called OPEN1 and OPEN2, just call the new key OPEN3. If no OPEN[id] keys are defined at all, just call it OPEN. Set the added key’s value to “/A [ProgID of your add-in]“.
Register during runtime
This is my prefered solution because we also have a plugin loaded in Excel. This plugin registers the UDF dynamically at startup. To do so, we need to add two lines of code to the startup-method of the addin.
using Excel = Microsoft.Office.Interop.Excel;
.
.
.
// Add the UDF to the loaded plugins.
Excel.AddIn addin = Application.AddIns.Add("UDF-progID");
// Set installed state to true.
addin.Installed = true;
Posted by ToM on under Debugging Tips |
A very helpful trick is to set an user environment variable called VSTO_SUPPRESSDISPLAYALERTS to 0, this gives you more detailed information what’s going wrong during runtime.
Posted by ToM on under Debugging Tips |
If some of the components don’t load correctly and seem to do really nothing, you’ve a great chance that one or more of the required dependencies can’t be loaded.
Windows offers you a possibility to inspect what exactly happens when the assemblies are loaded (or not *g*)…The fusion log.
To enable the fusion log, create a directory to retrieve the log’s output, let’s say c:\fusionlog.
Now, several registry keys need to be set in order to enable the logging:
- Set the path to your logfile directory in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogPath (in our example c:\fusionlog)
- Set HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogFailures to 1
- Optionally set HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\ForceLog to 1
- Optionally set HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\LogResourceBinds to 1
There’s a tool called “Assembly Binding Log Viewer” available in the .NET Framework SDK, for more information look here.