UDF Registration

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;
  • ToM said,

    We observed that something removed our registry OPEN values all the time when excel was started…after one week of searching around we figured out that our customer had an XLA addin named “removebrokenaddins” which removes all OPEN keys that reference to something else than XLA add-ins *lol* shit happens :-)