Create custom functions in Excel

Custom functions enable developers to add new functions to Excel by defining those functions in JavaScript as part of an add-in. Users within Excel can access custom functions just as they would any native function in Excel, such as SUM(). This article describes how to create custom functions in Excel.


Note that Excel custom functions are available on the following platforms.

  • Office on Windows (version 1904 or later, connected to Office 365 subscription)
  • Office on Mac (version 16.24 or later, connected to Office 365 subscription)
  • Office on the web

Excel custom functions are currently not supported on iPad or in one-time purchase versions of Office 2019 or earlier.

The following animated image shows your workbook calling a function you've created with JavaScript or Typescript. In this example, the custom function =MYFUNCTION.SPHEREVOLUME calculates the volume of a sphere.

animated image showing an end user inserting the MYFUNCTION.SPHEREVOLUME custom function into a cell of an Excel worksheet

The following code defines the custom function =MYFUNCTION.SPHEREVOLUME.

 * Returns the volume of a sphere. 
 * @customfunction
 * @param {number} radius
function sphereVolume(radius) {
  return Math.pow(radius, 3) * 4 * Math.PI / 3;


The Known issues section later in this article specifies current limitations of custom functions.

How a custom function is defined in code

If you use the Yo Office generator to create an Excel custom functions add-in project, you'll find that it creates files which control your functions, your task pane, and your add-in overall. We'll concentrate on the files that are important to custom functions:

File File format Description
Contains the code that defines custom functions.
./src/functions/functions.html HTML Provides a <script> reference to the JavaScript file that defines custom functions.
./manifest.xml XML Specifies the namespace for all custom functions within the add-in and the location of the JavaScript and HTML files that are listed previously in this table. It also lists the locations of other files your add-in might make use of, such as the task pane files and command files.

Script file

The script file (./src/functions/functions.js or ./src/functions/functions.ts) contains the code that defines custom functions and comments which define the function.

The following code defines the custom function add. The code comments are used to generate a JSON metadata file that describes the custom function to Excel. The required @customfunction comment is declared first, to indicate that this is a custom function. Additionally, you'll notice two parameters are declared, first and second, which are followed by their description properties. Finally, a returns description is given. For more information about what comments are required for your custom function, see Create JSON metadata for custom functions.

 * Adds two numbers.
 * @customfunction 
 * @param first First number.
 * @param second Second number.
 * @returns The sum of the two numbers.

function add(first, second){
  return first + second;

Note that the functions.html file, which governs the loading of the custom functions runtime, must link to the current CDN for custom functions. Projects prepared with the current version of the Yo Office generator reference the correct CDN. If you are retrofitting a previous custom function project from March 2019 or earlier, you need to copy in the code below to the functions.html page.

<script src="" type="text/javascript"></script>

Manifest file

The XML manifest file for an add-in that defines custom functions (./manifest.xml in the project that the Yo Office generator creates) specifies the namespace for all custom functions within the add-in and the location of the JavaScript, JSON, and HTML files.

The following basic XML markup shows an example of the <ExtensionPoint> and <Resources> elements that you must include in an add-in's manifest to enable custom functions. If using the Yo Office generator, your generated custom function files will contain a more complex manifest file, which you can compare on this Github repository.


The URLs specified in the manifest file for the custom functions JavaScript, JSON, and HTML files must be publicly accessible and have the same subdomain.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="" xmlns:xsi="" xmlns:bt="" xmlns:ov="" xsi:type="TaskPaneApp">
  <!--IMPORTANT! Id must be unique for each add-in. If you copy this manifest ensure that you change this id to your own GUID. -->
  <DisplayName DefaultValue="helloworld"/>
  <Description DefaultValue="Samples to test custom functions"/>
  <SupportUrl DefaultValue="[Insert the URL of a page that provides support information for the app]" />
    <Host Name="Workbook"/>
    <SourceLocation DefaultValue="https://localhost:8081/index.html"/>
  <VersionOverrides xmlns="" xsi:type="VersionOverridesV1_0">
      <Host xsi:type="Workbook">
          <ExtensionPoint xsi:type="CustomFunctions">
              <SourceLocation resid="JS-URL"/>
              <SourceLocation resid="HTML-URL"/>
              <SourceLocation resid="JSON-URL"/>
            <Namespace resid="namespace"/>
        <bt:Url id="JSON-URL" DefaultValue=""/>
        <bt:Url id="JS-URL" DefaultValue=""/>
        <bt:Url id="HTML-URL" DefaultValue=""/>
        <bt:String id="namespace" DefaultValue="CONTOSO"/>


Functions in Excel are prepended by the namespace specified in your XML manifest file. A function's namespace comes before the function name and they are separated by a period. For example, to call the function ADD42 in the cell of an Excel worksheet, you would type =CONTOSO.ADD42, because CONTOSO is the namespace and ADD42 is the name of the function specified in the JSON file. The namespace is intended to be used as an identifier for your company or the add-in. A namespace can only contain alphanumeric characters and periods.


Excel on the web and Windows connected to an Office 365 subscription allow you to coauthor documents and this feature works with custom functions. If your workbook uses a custom function, your colleague will be prompted to load the custom function's add-in. Once you both have loaded the add-in, the custom function will share results through coauthoring.

For more information on coauthoring, see About coauthoring in Excel.

Known issues

See known issues on our Excel Custom Functions GitHub repo.

Next steps

Want to try out custom functions? Check out the simple custom functions quick start or the more in-depth custom functions tutorial if you haven't already.

Another easy way to try out custom functions is to use Script Lab, an add-in that allows you to experiment with custom functions right in Excel. You can try out creating your own custom function or play with the provided samples.

Ready to read more about the capabilities custom functions? Learn about an overview of the custom functions architecture.

See also