You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
enumPLANETS {
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
+
returnvalue;
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
+
enumNUMBERS {
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
+
* @paraminput 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)
Copy file name to clipboardExpand all lines: docs/excel/custom-functions-parameter-options.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Options for Excel custom functions
3
3
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
5
5
ms.localizationpriority: medium
6
6
---
7
7
@@ -143,6 +143,9 @@ function secondHighest(values) {
143
143
144
144
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.
145
145
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
+
146
149
The following function sums the total of numbers, cell addresses, as well as ranges, if entered.
147
150
148
151
```TS
@@ -173,7 +176,7 @@ This function shows `=CONTOSO.ADD([operands], [operands]...)` in the Excel workb
173
176
174
177
### Repeating single value parameter
175
178
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.
177
180
178
181
```JS
179
182
/**
@@ -192,7 +195,7 @@ function addSingleValue(singleValue) {
192
195
193
196
### Single range parameter
194
197
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.
196
199
197
200
```JS
198
201
/**
@@ -212,15 +215,13 @@ function addSingleRange(singleRange) {
212
215
213
216
### Repeating range parameter
214
217
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).
218
219
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
220
221
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.
222
223
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.
Copy file name to clipboardExpand all lines: docs/excel/make-custom-functions-compatible-with-xll-udf.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ The manifest configuration depends on what type of manifest the add-in uses.
24
24
25
25
# [Unified manifest for Microsoft 365](#tab/jsonmanifest)
26
26
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).
0 commit comments