Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ _themes*/
_repo.*/
.vscode/

.openpublishing.buildcore.ps1
.openpublishing.buildcore.ps1
*DS_Store
15 changes: 9 additions & 6 deletions docs/develop/script-buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Run Office Scripts in Excel from buttons
description: Add buttons to workbooks that control Office Scripts in Excel.
ms.topic: overview
ms.date: 06/06/2024
ms.date: 02/26/2026
ms.localizationpriority: medium
---

Expand All @@ -17,18 +17,21 @@ Help your colleagues find and run your scripts by adding script buttons to a wor

## Create script buttons

When viewing a script, select **Add in workbook**. This creates a button in the workbook that runs the associated script. It also shares the script with the workbook, so everyone with write permissions to the workbook can use your helpful automation.
When viewing a script, scroll to the **Share this script** section and enable the **Associate with workbook** toggle. This shares the script with the workbook, so everyone with write permissions to the workbook can use your helpful automation. Select **Add button to worksheet** to create a button in the worksheet that runs the associated script.

:::image type="content" source="../images/add-button.png" alt-text="The 'Add in workbook' button on the 'Create Report' script details page with a button named 'Create Report' shown in the Excel grid.":::
:::image type="content" source="../images/add-button.png" alt-text="The 'Associate with workbook' and 'Add button to worksheet' controls in the Share this script section.":::

> [!IMPORTANT]
> If OneDrive sharing is restricted by organizational policies, you can't create a script button.
> If OneDrive sharing is restricted by organizational policies, you can't associate a script or create a script button.

## Remove script buttons

To stop sharing a script through a button, select the arrow next to **Add in workbook** and choose the option **Remove from workbook**. This removes all the buttons that run the script. Deleting a single button removes the script from that one button, even if the operation is undone or the button is cut and pasted.
To stop sharing a script, disable the **Associate with workbook** toggle in the **Share this script** section of the script details page. This removes all the buttons that run the script from the workbook.

:::image type="content" source="../images/remove-button.png" alt-text="The 'Remove from workbook' option on the script details page.":::
:::image type="content" source="../images/associate-with-workbook.png" alt-text="The 'Share this script' section of the script details page, with the 'Associate with workbook' toggle enabled.":::

> [!IMPORTANT]
> Deleting a script button from the Excel grid removes that button, but the script still remains associated with the workbook.

## Older versions of Excel

Expand Down
16 changes: 8 additions & 8 deletions docs/develop/typescript-restrictions.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: TypeScript restrictions in Office Scripts
description: The specifics of the TypeScript compiler and linter used by the Office Scripts Code Editor.
ms.date: 11/21/2025
description: The specifics of the TypeScript compiler and linter used by the Office Scripts code editor.
ms.date: 02/26/2026
ms.localizationpriority: medium
---

# TypeScript restrictions in Office Scripts

Office Scripts use the TypeScript language. For the most part, any TypeScript or JavaScript code will work in Office Scripts. However, there are a few restrictions enforced by the Code Editor to ensure your script works consistently and as intended with your Excel workbook.
Office Scripts use the TypeScript language. For the most part, any TypeScript or JavaScript code will work in Office Scripts. However, there are a few restrictions enforced by the code editor to ensure your script works consistently and as intended with your Excel workbook.

> [!NOTE]
> Office Scripts uses TypeScript version 4.0.3. TypeScript features added in subsequent versions are not supported in Office Scripts.
Expand All @@ -20,19 +20,19 @@ Writing [types](https://www.typescriptlang.org/docs/handbook/typescript-in-5-min

You cannot explicitly declare a variable to be of type `any` in Office Scripts (that is, `let value: any;`). The `any` type causes issues when processed by Excel. For example, a `Range` needs to know that a value is a `string`, `number`, or `boolean`. You will receive a compile-time error (an error prior to running the script) if any variable is explicitly defined as the `any` type in the script.

:::image type="content" source="../images/explicit-any-editor-message.png" alt-text="The explicit `any` message in the Code Editor's hover text.":::
:::image type="content" source="../images/explicit-any-editor-message.png" alt-text="The explicit `any` message in the code editor's hover text.":::

:::image type="content" source="../images/explicit-any-error-message.png" alt-text="The explicit `any` error in the console window.":::

In the previous screenshot, `[2, 14] Explicit Any is not allowed` indicates that line #2, column #14 defines `any` type. This helps you locate the error.
In the previous screenshot, `[6, 14] Explicit Any is not allowed` indicates that line #6, column #14 defines `any` type. This helps you locate the error.

To get around this issue, always define the type of the variable. If you are uncertain about the type of a variable, you can use a [union type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types). This can be useful for variables that hold `Range` values, which can be of type `string`, `number`, or `boolean` (the type for `Range` values is a union of those: `string | number | boolean`).

### Implicit `any`

TypeScript variable types can be [implicitly](https://www.typescriptlang.org/docs/handbook/type-inference.html) defined. If the TypeScript compiler is unable to determine the type of a variable (either because type is not defined explicitly or type inference isn't possible), then it's an implicit `any` and you will receive a compilation-time error.

:::image type="content" source="../images/implicit-any-editor-message.png" alt-text="The implicit `any` message in the Code Editor's hover text.":::
:::image type="content" source="../images/implicit-any-editor-message.png" alt-text="The implicit `any` message in the code editor's hover text.":::

The most common case on any implicit `any` is in a variable declaration, such as `let value;`. There are two ways to avoid this:

Expand Down Expand Up @@ -72,7 +72,7 @@ let filteredArray = myArray.filter((x) => {
return x % 2 === 0;
});
/*
The following code generates a compiler error in the Office Scripts Code Editor.
The following code generates a compiler error in the Office Scripts code editor.
filteredArray = myArray.filter(function (x) {
return x % 2 === 0;
});
Expand Down Expand Up @@ -125,7 +125,7 @@ function main(workbook: ExcelScript.Workbook) {

## Performance warnings

The Code Editor's [linter](https://wikipedia.org/wiki/Lint_(software)) gives warnings if the script might have performance issues. The cases and how to work around them are documented in [Improve the performance of your Office Scripts](web-client-performance.md).
The code editor [linter](https://wikipedia.org/wiki/Lint_(software)) gives warnings if the script might have performance issues. The cases and how to work around them are documented in [Improve the performance of your Office Scripts](web-client-performance.md).

## External API calls

Expand Down
Binary file modified docs/images/action-recorder-copy-code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/action-recorder-intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/add-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/associate-with-workbook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/code-editor-intro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/explicit-any-editor-message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/explicit-any-error-message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/implicit-any-editor-message.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/runtime-error-console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/share-this-script.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions docs/overview/code-editor-environment.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
title: Office Scripts Code Editor environment
description: The prerequisites and environment information for Office Scripts in Excel.
ms.date: 11/01/2023
title: Office Scripts code editor
description: Learn about the Office Scripts code editor and scripting environment in Excel, including prerequisites and supported APIs.
ms.date: 02/06/2026
ms.localizationpriority: medium
---

# Office Scripts Code Editor environment
# Office Scripts code editor

Office Scripts are written in either TypeScript or JavaScript and use the Office Scripts JavaScript APIs to interact with an Excel workbook. The Code Editor is based on Visual Studio Code, so if you've used that environment before, you'll feel right at home.
Office Scripts are written in either TypeScript or JavaScript and use the Office Scripts JavaScript APIs to interact with an Excel workbook. The Office Scripts code editor is based on Visual Studio Code, so if you've used that environment before, you'll feel right at home.

## Scripting language: TypeScript or JavaScript

Office Scripts are written in [TypeScript](https://www.typescriptlang.org/docs), which is a superset of [JavaScript](https://developer.mozilla.org/docs/Web/JavaScript). The Action Recorder generates code in TypeScript and the Office Scripts documentation uses TypeScript. Since TypeScript is a superset of JavaScript, any scripting code that you write in JavaScript will work just fine.
Office Scripts are written in [TypeScript](https://www.typescriptlang.org/docs), which is a superset of [JavaScript](https://developer.mozilla.org/docs/Web/JavaScript). The action recorder generates code in TypeScript and the Office Scripts documentation uses TypeScript. Since TypeScript is a superset of JavaScript, any scripting code that you write in JavaScript will work just fine.

Office Scripts are largely self-contained pieces of code. Only a small part of TypeScript's functionality is used. Therefore, you can edit scripts without having to learn the intricacies of TypeScript. The Code Editor also handles the installation, compilation, and execution of code, so you don't need to worry about anything but the script itself. It's possible to learn the language and create scripts without previous programming knowledge. However, if you're new to programming, we recommend learning some fundamentals before proceeding with Office Scripts.
Office Scripts are largely self-contained pieces of code. Only a small part of TypeScript's functionality is used. Therefore, you can edit scripts without having to learn the intricacies of TypeScript. The code editor also handles the installation, compilation, and execution of code, so you don't need to worry about anything but the script itself. It's possible to learn the language and create scripts without previous programming knowledge. However, if you're new to programming, we recommend learning some fundamentals before proceeding with Office Scripts.

[!INCLUDE [Recommended coding resources](../includes/coding-basics-references.md)]

Expand All @@ -27,19 +27,19 @@ Office Scripts does not support the usage of external, third-party JavaScript li

## IntelliSense

IntelliSense is a set of Code Editor features that help you write code. It provides auto-complete, syntax error highlighting, and inline API documentation.
IntelliSense is a set of code editor features that help you write code. It provides auto-complete, syntax error highlighting, and inline API documentation.

IntelliSense gives suggestions as you type, similar to the suggested text in Excel. Pressing the <kbd>Tab</kbd> or <kbd>Enter</kbd> key inserts the suggested member. Trigger IntelliSense at the current cursor location by pressing the <kbd>Ctrl</kbd>+<kbd>Space</kbd> keys. These suggestions are especially useful when completing a method. The method signature displayed by IntelliSense contains a list of arguments it needs, each argument's type, whether a given argument is required or optional, and the return type of the method.
IntelliSense gives suggestions as you type, similar to the suggested text in Excel. Using the <kbd>Tab</kbd> or <kbd>Enter</kbd> key inserts the suggested member. Trigger IntelliSense at the current cursor location with the <kbd>Ctrl</kbd>+<kbd>Space</kbd> keys. These suggestions are especially useful when completing a method. The method signature displayed by IntelliSense contains a list of arguments it needs, each argument's type, whether a given argument is required or optional, and the return type of the method.

Hover the cursor over a method, class, or other code object to see more information. Hover over a syntax error or code suggestion, represented by a red or yellow squiggly line, to see suggestions on how to fix the problem. Often, IntelliSense provides a "Quick Fix" option to automatically change the code.

:::image type="content" source="../images/implicit-any-editor-message.png" alt-text="An error message in the Code Editor's hover text with a 'Quick Fix' button.":::
:::image type="content" source="../images/implicit-any-editor-message.png" alt-text="An error message in the code editor's hover text with a 'Quick Fix' button.":::

The Office Scripts Code Editor uses the same IntelliSense engine as Visual Studio Code. To learn more about the feature, visit [Visual Studio Code's IntelliSense Features](https://code.visualstudio.com/docs/editor/intellisense#_intellisense-features).
The Office Scripts code editor uses the same IntelliSense engine as Visual Studio Code. To learn more about the feature, visit [Visual Studio Code's IntelliSense Features](https://code.visualstudio.com/docs/editor/intellisense#_intellisense-features).

## Keyboard shortcuts

Most of the keyboard shortcuts for Visual Studio Code also work in the Office Scripts Code Editor. Use the following PDFs to learn about the available options and get the most out of the Code Editor:
Most of the keyboard shortcuts for Visual Studio Code also work in the Office Scripts code editor. Use the following PDFs to learn about the available options and get the most out of the code editor:

- [Keyboard shortcuts for macOS](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf).
- [Keyboard shortcuts for Windows](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf).
Expand Down
Loading
Loading