Contact

Microsoft Excel · Automation bounded introductory track · Intermediate

Edit and share one Office Script with permission checks

Edit a small Office Script, inspect its access boundary, and distinguish workbook association from a removable worksheet button.

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

Quick answer: Edit and test your own script first. To make it available through a workbook, enable Share this script > Associate with workbook only after reviewing that workbook’s audience. To stop that association, turn the toggle off; deleting a worksheet button alone does not unshare the script.

Requirements and permission boundary

Use English Excel for Microsoft 365 desktop on Windows, Version 2210 or later, with an eligible business or education subscription, OneDrive for Business, internet connectivity, connected experiences already enabled, and “People in your organization” sharing links already permitted. Office Scripts must already be enabled; do not change privacy or sharing policy to meet these prerequisites. This workbook-sharing workflow is not supported for personal/family accounts. Organizational sharing policy can prevent association even when you can run a private script.

Use your own script and a private test workbook. The procedure describes sharing but does not perform it for you. Associate only with a workbook whose existing audience you have reviewed and are authorized to include. Do not add colleagues or broaden permissions merely to finish a practice exercise.

Workbook association links the script; it does not embed an independent copy in the XLSX. The script normally remains in its creator’s OneDrive. Workbook access can expose the script for viewing, running, or copying, while write permission is required for the documented workbook automation use. This is different from granting permission to edit the original script file. A copied script is independent; later changes to the original do not update that copy.

Prepare and edit a harmless script

In a practice workbook, enter this data at A1:C3:

Fruit	Prior	Current
Oranges	100	120
Lemons	80	90

Record your own Office Script that colors A2:C2 orange through Automate > New Script > Create from Recording, then stop. From Details choose Edit. The introductory Microsoft tutorial uses this pattern:

function main(workbook: ExcelScript.Workbook) {
  let selectedSheet = workbook.getActiveWorksheet();
  selectedSheet.getRange("A2:C2").getFormat().getFill().setColor("FFC000");
}

Add the following statement before the final closing brace:

selectedSheet.getRange("A3:C3").getFormat().getFill().setColor("yellow");

Review the entire script before running it. These statements only change fill colors in the active worksheet. They do not send data externally, create files, change cell values, or expand sharing. Preserve the original script if you need a comparison copy.

Test before associating

With the intended practice sheet active, select Run. A2:C2 should be orange and A3:C3 yellow; the header row should be unchanged. The Current values remain 120 and 90, totaling 210.

Change C3 to 95 and rerun. The total becomes 215 and must remain 215 after formatting. Reset the fills and run again to check that both range operations work. Confirm the edited script is saved and reopen it from Automate before sharing so you are not relying on an unsaved editor state.

Associate and remove deliberately

  1. Review the test workbook’s current access. If you cannot determine its audience, stop before associating.
  2. In the script details, find Share this script and enable Associate with workbook only for the authorized audience.
  3. Optionally select Add button to worksheet to create an easy run control. A button is an interface to the association, not the permission itself.
  4. Verify that the linked script is the reviewed formatting routine. Never put secrets in code that workbook users may view or copy.
  5. To stop sharing through that workbook, disable Associate with workbook. Microsoft’s documented behavior removes the workbook’s buttons that run that script.

Deleting only a button from the grid leaves the script associated. Disabling association also cannot recall an independent copy someone already made or revoke unrelated direct OneDrive/SharePoint permissions. Treat those as separate access paths.

Save and troubleshoot

Save the workbook and reopen it under the supported account. Check the script’s association state, not just whether a button appears. In older Excel versions, a button can remain visible but do nothing. If policy prevents association, do not work around it by moving code to an unauthorized sharing location.

For checking unchanged numeric data, see SUM. Keep the original private script and workbook until you have verified both the formatting and the intended sharing boundary.

Official references