How to reload Excel custom functions?

Viewed 835

I've deployed the Excel-Custom-Functions sample successfully and can use the new JS functions.

After changing the code/definition in customfunctions.js, I've restarted my web server, started Excel, inserted the custom functions from the Office Add-ins page again but still get the original functions.

If I start Excel without inserting the sample again, the functions are still known!?

How can I force Excel to remove such an add-in and reload it from scratch?

Example: The sample contains several custom functions and their corresponding registration:

Excel.Script.CustomFunctions["CONTOSO"]["ADD42"] = {
...
Excel.Script.CustomFunctions["CONTOSO"]["GETTEMPERATURE"] = {
...

Rename a function, and remove another function completely:

Excel.Script.CustomFunctions["CONTOSO"]["ADD42RENAMED"] = {
...
/* Excel.Script.CustomFunctions["CONTOSO"]["GETTEMPERATURE"] = {
...

Excel will still show the old metadata afterwards.

1 Answers

Excel caches previously-registered functions for each add-in. The reason for caching is so that the functions are available for the user to see and trigger (causing your add-in to load automatically) even before the add-in gets loaded.

When you run the following code, all previous registered functions in the cache are removed and immediately replaced with the new ones you specify:

Excel.run(function (context) {        
    context.workbook.customFunctions.addAll();
    return context.sync().then(function(){});
}).catch(function(error){});

Edit: if you still see functions that you don't think are supposed to be registered after you call the code above, there are 2 likely possibilities:

  1. The "incorrect" functions were actually registered by a different add-in (perhaps an earlier test you were doing).
  2. The Excel.run call is failing (you can check the error parameter to see whether this is your problem)

It may be useful to manually clear your computer's registration-cache: delete the folder AppData\Local\Microsoft\Office\16.0\Wef\CustomFunctions

-Michael, PM for add-ins

Related