0x800a138f - JavaScript runtime error: Unable to set property 'CustomFunctions' of undefined or null reference


I'm newly developing office Add-Ins. I was able to create an Excel add-in using visual studio 2019 with Office / SharePoint development workload (JavaScrip APIs). On the other hand, I'm trying to execute this example:https://github.com/lindalu-MSFT/Excel-Custom-Functions#prerequisites

The point is: Executing the solution, the excel runs but there is an error on this line of Home.js:

Excel.Script.CustomFunctions = {};

The error:

0x800a138f - JavaScript runtime error: Unable to set property 'CustomFunctions' of undefined or null reference

This is my HTML code:

<!DOCTYPE html>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Expires" content="0" />
    <title>Excel Add-In with Commands Sample</title>
    <script src="Scripts/jquery-3.5.0.js" type="text/javascript"></script>
    <script src="https://appsforoffice.edog.officeapps.live.com/lib/beta/hosted/office.js" type="text/javascript"></script>
    <script src="Home.js" type="text/javascript"></script>

This is my XML code:

<?xml version="1.0" encoding="UTF-8"?>
  <DisplayName DefaultValue="Custom functions sample" />
  <Description DefaultValue="A variety of sample custom functions."/>
    <Host Name="Workbook" />
    <SourceLocation DefaultValue="~remoteAppUrl/Home.html" />          
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
      <Host xsi:type="Workbook">
          <ExtensionPoint xsi:type="CustomFunctions">    
              <SourceLocation resid="functionsjs" />     
              <SourceLocation resid="functionshtml"/>   
        <bt:Url id="functionsjs" DefaultValue="~remoteAppUrl/Home.js" />
        <bt:Url id="functionshtml" DefaultValue="~remoteAppUrl/Home.html" />

and finally the js code:

Office.initialize = function (reason) {
    // Define the Contoso prefix.
    Excel.Script.CustomFunctions = {};
    Excel.Script.CustomFunctions["CONTOSO"] = {};

    // add42 is an example of a synchronous function.
    function add42(a, b) {
        return a + b + 42;
    Excel.Script.CustomFunctions["CONTOSO"]["ADD42"] = {
        call: add42,
        description: "Finds the sum of two numbers and 42.",
        helpUrl: "https://www.contoso.com/help.html",
        result: {
            resultType: Excel.CustomFunctionValueType.number,
            resultDimensionality: Excel.CustomFunctionDimensionality.scalar,
        parameters: [
                name: "num 1",
                description: "The first number",
                valueType: Excel.CustomFunctionValueType.number,
                valueDimensionality: Excel.CustomFunctionDimensionality.scalar,
                name: "num 2",
                description: "The second number",
                valueType: Excel.CustomFunctionValueType.number,
                valueDimensionality: Excel.CustomFunctionDimensionality.scalar,
        options: { batch: false, stream: false }

    Excel.run(function (context) {
        return context.sync();
    }).catch(function (error) { });
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));

Can you guys help me with a direction to solve this problem?

I checked these topics:

Stack question

excel package

create custom functions

asked on Stack Overflow Mar 5, 2021 by DeSanterra • edited Mar 5, 2021 by Rick Kirkham

1 Answer


I think that is some one's old fork for custom functions, so you're likely trying to access a version of this that was in preview and doesn't work any longer as our interfaces have changed.

Please refer to the official guidence on custom functions here: https://aka.ms/customfunctions

answered on Stack Overflow Mar 5, 2021 by Keyur Patel - MSFT

User contributions licensed under CC BY-SA 3.0