Skip to content

Commit 4faaf7f

Browse files
authored
Merge pull request #5265 from OfficeDev/main
[Admin] Publish
2 parents 66322c0 + 991b1ed commit 4faaf7f

5 files changed

+133
-10
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
title: Custom enums for custom functions
3+
description: Create custom enums to use with your custom functions.
4+
ms.date: 06/24/2025
5+
ms.localizationpriority: medium
6+
---
7+
8+
# Create custom enums for your custom functions
9+
10+
:::image type="content" source="../images/custom-functions-custom-enum-autocomplete.png" alt-text="The members of a custom enum displaying in the Excel AutoComplete menu.":::
11+
12+
Custom enums give users Excel AutoComplete options for your custom functions. The members in your enum show up in the formula bar as suggestions. The planets in the preceding screenshot are an example of a custom enum that provides a set list. This article describes how to create custom enums and use them as parameters in your custom functions.
13+
14+
## Define the custom enum
15+
16+
Define your enum with the JSDoc tag `@customenum`. The corresponding JSON properties are then autogenerated in your custom function metadata. For more information about JSDoc tags and custom functions, see [Basics of JSDoc tags](custom-functions-json-autogeneration.md#basics-of-jsdoc-tags).
17+
18+
> [!NOTE]
19+
> Custom enums created with the `@customenum` JSDoc tag are only supported in TypeScript. They are not supported in JavaScript. To use custom enums with JavaScript functions, you must manually create your own JSON metadata. To learn more, see [Manually create JSON metadata](custom-functions-json.md).
20+
21+
The following code snippet shows how to define and use a simple custom enum as a parameter.
22+
23+
```typescript
24+
/**
25+
* A custom enum with descriptions and tooltips.
26+
* @customenum {string}
27+
*/
28+
enum PLANETS {
29+
/** Mercury is the first planet from the sun. */
30+
mercury = "Mercury",
31+
32+
/** Venus is the second planet from the sun. */
33+
venus = "Venus",
34+
35+
/** Earth is the third planet from the sun. */
36+
earth = "Earth",
37+
}
38+
39+
/**
40+
* A sample function that uses the custom enum as a parameter.
41+
* @customfunction
42+
*/
43+
function getPlanets(value: PLANETS): any {
44+
return value;
45+
}
46+
```
47+
48+
## Use a custom enum multiple times
49+
50+
A custom enum can be reused in multiple functions, and it can be used as multiple parameters of a single function. A function can also have multiple enums as parameters at the same time. An enum parameter can be repeating or optional.
51+
52+
The following code sample shows a `NUMBERS` enum and a custom function that uses the enum multiple times as an input value.
53+
54+
```typescript
55+
/**
56+
* Enum of numbers with descriptions and tooltips.
57+
* @customenum {number}
58+
*/
59+
enum NUMBERS {
60+
/** One */
61+
One = 1,
62+
63+
/** Two */
64+
Two = 2,
65+
66+
/** Three */
67+
Three = 3,
68+
69+
/** Four */
70+
Four = 4,
71+
72+
/** Five */
73+
Five = 5
74+
}
75+
76+
/**
77+
* Enter multiple numbers from the NUMBERS enum and get the sum.
78+
* @customfunction
79+
* @param input Enter enum numbers.
80+
* @returns
81+
*/
82+
function addNumbers(input: NUMBERS[]): any {
83+
const sum = input.reduce((acc, num) => acc + num, 0);
84+
return "Sum: " + sum;
85+
}
86+
```
87+
88+
## Localize your custom enums
89+
90+
Localizing custom enums is similar to [localizing custom functions](custom-functions-naming.md#localize-custom-functions). You must [manually create your JSON metadata](custom-functions-json.md) and then create a new JSON metadata file for each language.
91+
92+
Note that only the `name` and `tooltip` properties within an enum should be localized to the target language. The `value` property should remain unchanged to avoid the need for handling multiple languages within your function body.
93+
94+
The following JSON snippet shows the Chinese language localized `values` object for the planet Mercury.
95+
96+
```json
97+
"enums": [
98+
{
99+
"id": "PLANETS",
100+
"type": "string",
101+
"values": [
102+
{
103+
"name": "水星",
104+
"value": "mercury",
105+
"tooltip": "水星是距离太阳最近的行星"
106+
}
107+
]
108+
}
109+
],
110+
```
111+
112+
## Backwards compatibility
113+
114+
Custom enums offer backwards compatibility. On older versions of Excel, parameters using a custom enum work as standard parameters without displaying in the Excel AutoComplete list.
115+
116+
## See also
117+
118+
- [Manually create JSON metadata for custom functions](custom-functions-json.md)
119+
- [Autogenerate JSON metadata for custom functions](custom-functions-json-autogeneration.md)

docs/excel/custom-functions-parameter-options.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Options for Excel custom functions
33
description: Learn how to use different parameters within your custom functions, such as Excel ranges, optional parameters, invocation context, and more.
4-
ms.date: 07/05/2023
4+
ms.date: 06/26/2025
55
ms.localizationpriority: medium
66
---
77

@@ -143,6 +143,9 @@ function secondHighest(values) {
143143

144144
A repeating parameter allows a user to enter a series of optional arguments to a function. When the function is called, the values are provided in an array for the parameter. If the parameter name ends with a number, each argument's number will increase incrementally, such as `ADD(number1, [number2], [number3],…)`. This matches the convention used for built-in Excel functions.
145145

146+
> [!NOTE]
147+
> For a custom function that takes multiple parameters, a repeating parameter must be the last input parameter in the function. A repeating parameter cannot be followed by another parameter. Similarly, a function can only have one repeating parameter.
148+
146149
The following function sums the total of numbers, cell addresses, as well as ranges, if entered.
147150

148151
```TS
@@ -173,7 +176,7 @@ This function shows `=CONTOSO.ADD([operands], [operands]...)` in the Excel workb
173176

174177
### Repeating single value parameter
175178

176-
A repeating single value parameter allows multiple single values to be passed. For example, the user could enter ADD(1,B2,3). The following sample shows how to declare a single value parameter.
179+
A repeating single value parameter allows multiple single values to be passed. For example, the user could enter **ADD(1,B2,3)**. The following sample shows how to declare a single value parameter.
177180

178181
```JS
179182
/**
@@ -192,7 +195,7 @@ function addSingleValue(singleValue) {
192195

193196
### Single range parameter
194197

195-
A single range parameter isn't technically a repeating parameter, but is included here because the declaration is very similar to repeating parameters. It would appear to the user as ADD(A2:B3) where a single range is passed from Excel. The following sample shows how to declare a single range parameter.
198+
A single range parameter isn't technically a repeating parameter, but it's included here because the declaration is very similar to repeating parameters. It would appear to the user as **ADD(A2:B3)**, where a single range is passed from Excel. The following sample shows how to declare a single range parameter.
196199

197200
```JS
198201
/**
@@ -212,15 +215,13 @@ function addSingleRange(singleRange) {
212215

213216
### Repeating range parameter
214217

215-
A repeating range parameter allows multiple ranges or numbers to be passed. For example, the user could enter ADD(5,B2,C3,8,E5:E8). Repeating ranges are usually specified with the type `number[][][]` as they are three-dimensional matrices. For a sample, see the main sample listed for [repeating parameters](#repeating-parameters).
216-
217-
### Declaring repeating parameters
218+
A repeating range parameter allows multiple ranges or numbers to be passed. For example, the user could enter **ADD(5,B2,C3,8,E5:E8)**. Repeating ranges are usually specified with the type `number[][][]` as they are three-dimensional matrices. For a sample, see the main sample listed for [repeating parameters](#repeating-parameters).
218219

219-
In Typescript, indicate that the parameter is multi-dimensional. For example, `ADD(values: number[])` would indicate a one-dimensional array, `ADD(values:number[][])` would indicate a two-dimensional array, and so on.
220+
### Declare repeating parameters
220221

221-
In JavaScript, use `@param values {number[]}` for one-dimensional arrays, `@param <name> {number[][]}` for two-dimensional arrays, and so on for more dimensions.
222+
To declare a repeating parameter, indicate that the parameter is multi-dimensional. For example in TypeScript, `ADD(values: number[])` would indicate a one-dimensional array, `ADD(values:number[][])` would indicate a two-dimensional array, and so on. In JavaScript, use `@param values {number[]}` for one-dimensional arrays, `@param <name> {number[][]}` for two-dimensional arrays, and so on for more dimensions.
222223

223-
For hand-authored JSON, ensure your parameter is specified as ``"repeating"`: true` in your JSON file, as well as check that your parameters are marked as ``"dimensionality"`: matrix`.
224+
For [manually-created JSON metadata](custom-functions-json.md), ensure that the parameter is specified as `"repeating": true` and `"dimensionality": "matrix"` in your JSON file.
224225

225226
## Invocation parameter
226227

docs/excel/make-custom-functions-compatible-with-xll-udf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The manifest configuration depends on what type of manifest the add-in uses.
2424

2525
# [Unified manifest for Microsoft 365](#tab/jsonmanifest)
2626

27-
The following example shows how to specify both a COM add-in and an XLL add-in as equivalents in a unified manifest. Often you specify both. For completeness, this example shows both equivalents in context. They're identified by their [`"alternates.prefer.comAddin.progId"`](/microsoft-365/extensibility/schema/extension-alternate-versions-array-prefer-com-addin#progid) and [`"alternates.prefer.xllCustomFunctions.filename"`](/microsoft-365/extensibility/schema/extension-alternate-versions-array-prefer-xll-custom-functions#filename) respectively. For more information on COM add-in compatibility, see [Make your Office Add-in compatible with an existing COM add-in](../develop/make-office-add-in-compatible-with-existing-com-add-in.md).
27+
The following example shows how to specify both a COM add-in and an XLL add-in as equivalents in a unified manifest. Often you specify both. For completeness, this example shows both equivalents in context. They're identified by their [`"alternates.prefer.comAddin.progId"`](/microsoft-365/extensibility/schema/extension-alternate-versions-array-prefer-com-addin#progid) and `"alternates.prefer.xllCustomFunctions.filename"` respectively. For more information on COM add-in compatibility, see [Make your Office Add-in compatible with an existing COM add-in](../develop/make-office-add-in-compatible-with-existing-com-add-in.md).
2828

2929
```json
3030
"extensions" [
75.6 KB
Loading

docs/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ items:
677677
- name: Manually create JSON metadata
678678
href: excel/custom-functions-json.md
679679
displayName: Excel, Custom Functions
680+
- name: Custom enums
681+
href: excel/custom-functions-custom-enums.md
682+
displayName: Excel, Custom Functions
680683
- name: Call Excel JavaScript APIs
681684
href: excel/call-excel-apis-from-custom-function.md
682685
displayName: Excel, Custom Functions

0 commit comments

Comments
 (0)