Contact

Microsoft Excel · Automation bounded introductory track · Intermediate

Record and rerun an Office Script

Record a format-only Office Script, inspect its range, and rerun it on a controlled second worksheet.

Official documentation reviewed; synthetic fixtures checked independently; not executed in Excel · Editorial standards

Quick answer: On Automate, choose New Script > Create from Recording, perform a small formatting action, and stop. Inspect the generated script before rerunning it on a sheet with the same layout. A recording targets the addresses it captured, not whatever cells you happen to select later.

Requirements and scope

Use English Excel for Microsoft 365 desktop on Windows, Version 2210 or later, with an already eligible business or education subscription, OneDrive for Business, internet connectivity, connected experiences already enabled, and existing permission for “People in your organization” sharing links. Office Scripts must already be enabled by your organization; do not change privacy or sharing policy for this exercise. The Automate tab must be available. These prerequisites do not mean every API works in every client build; this example uses the simple formatting API in Microsoft’s introductory tutorial.

This guide does not use personal/family preview behavior, Power Automate, scheduling, external requests, or workbook sharing. It describes existing account-dependent features without creating or connecting accounts. Office Scripts are stored separately from workbook cells, normally in OneDrive, so saving an XLSX is not the same as embedding a VBA macro.

Prepare the practice sheet

On a new sheet named Practice, enter the following at A1:C3:

Fruit	Prior	Current
Oranges	100	120
Lemons	80	90

The Current column totals 210. Keep a saved workbook copy before recording. This exercise will color the Oranges row only; it will not create a table, sort rows, insert data, or change quantities. Repeating a format-only action is easier to validate than repeating a structural action such as adding a table on top of an existing table.

Record and inspect

  1. Open the Automate tab. If it is not visible, check ribbon overflow; if still absent, verify eligibility and organizational availability rather than installing an unrelated automation tool.
  2. Choose New Script > Create from Recording.
  3. Select A2:C2 and set its fill to orange.
  4. Select Stop. Give the script a descriptive name such as ColorOrangesRow in its details/name area.
  5. From Details, choose Edit and inspect the generated code.

Microsoft’s tutorial shows the essential pattern: get the active worksheet, then set the fill color of a specific range. Your recording should reference A2:C2 and a fill-color operation, without data-writing or external calls. The exact orange color code can vary with the chosen swatch; that is not a different target range.

Reset and rerun

After recording has stopped, manually remove the orange fill from A2:C2. Keep Practice active, then select Run for the script. The same three cells should become orange again. A1:C1 and A3:C3 should not change, and the numeric values remain 100,120,80,90.

Change C2 from 120 to 125. The Current total becomes 215. Reset the fill and rerun; the script must restore the color without restoring C2 to 120. A formatting recording should preserve the edited value.

Create another blank worksheet named Repeat, paste the same starting block at A1:C3, and run the script with Repeat active. Check that Repeat!A2:C2 is colored and that Practice retains its own changed C2=125. This explicitly tests the active-worksheet behavior rather than assuming a script is permanently attached to the original sheet.

Save, reopen, and troubleshoot

Save the workbook as XLSX and reopen it while signed in to the same authorized account. Locate the named script through Automate, inspect it, and rerun only on the intended practice layout. Access to the separately stored script requires the supported account and connection; the workbook alone is not a portable script archive.

If the wrong row changes, inspect the recorded address and active sheet. If rerunning a different recording fails because a table already exists, recognize that structural operations are not necessarily repeatable unchanged. For this exercise, retain only the bounded formatting operation. Use SUM for the independent 210/215 value check.

Official references