Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
When a user is actively editing a cell, some add-in operations may fail immediately. Use the delayForCellEdit option to queue the batch until the user exits cell edit mode instead of throwing an error.
Excel.run has an overload that takes an Excel.RunOptions object. It supports the following property relevant to this scenario.
delayForCellEdit: Whentrue, Excel queues the batch until the user exits cell edit mode. Whenfalse, the batch fails immediately if the user is editing. The default value isfalse.
Behavior comparison
| User editing? | delayForCellEdit = false (default) |
delayForCellEdit = true |
|---|---|---|
| No | Batch runs immediately | Batch runs immediately |
| Yes | Batch fails (InvalidOperation error) |
Batch waits; then runs after edit is committed or canceled |
Example
await Excel.run({ delayForCellEdit: true }, async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
const range = sheet.getRange("A1");
range.values = [["Updated while user was editing elsewhere"]];
await context.sync();
});
Guidance
- Use
delayForCellEditonly when user-initiated commands may overlap active cell editing, such as with a ribbon button that triggers a bulk update. - Consider showing a status indicator in your add-in if queued work may be lengthy.
- Avoid chaining multiple long-running delayed batches. This creates a perceived lag for your users.
Next steps
Explore related user-state strategies in Events, such as reacting to selection changes, and combine with delayForCellEdit to improve your add-in's robustness.
Office Add-ins