Excel Office Scripts Cannot Programmatically Add Worksheet Buttons
Question details
The user wants to add a worksheet button linked to an Office Script through code in Excel.

- Product
- Microsoft Excel Office Scripts
- Device & OS
- not provided
- Scenario
- The user is automating worksheet creation and wants each generated sheet to include a button that runs an Office Script.
- Observed behavior
- Office Scripts can create and modify worksheets, but they cannot programmatically create worksheet buttons or assign scripts to new buttons.
Create and test the Office Script that the button should run before building the worksheet template. Add the required script button manually to a template worksheet and confirm that it works in Excel for the web.
Copy a Template Worksheet That Already Contains the Office Script Button
Use this supported workaround when new worksheets need the same preconfigured button and layout.
Office Scripts do not currently provide an API to create worksheet buttons or link a newly created button to a script. Instead, set up one template worksheet with the button already assigned, then duplicate that worksheet in your automation.
In Excel for the web, add a worksheet that contains the required layout, tables, formulas, and content.
Open the Automate tab, select the Office Script you want to run, and use Add button to place its button on the template worksheet.
Select the button on the worksheet and verify that it runs the intended Office Script successfully.
In the Office Scripts editor, use workbook.getWorksheet("Template").copy() to create a copy of the prepared worksheet, then rename the copied sheet as needed.

Use a Clearly Named Template Sheet for Repeated Automation
Use this approach when your script creates many similar sheets and users need a consistent button on every sheet.
Use WPS Office for Familiar Spreadsheet and Macro Workflows
Excel Office Scripts does not currently support creating worksheet buttons programmatically. For everyday spreadsheet automation and macro-oriented work, WPS Office provides a free, lightweight office suite with a familiar spreadsheet interface, practical VBA macro support, and a smooth transition for users working with Excel files.

Frequently Asked Questions
Can Office Scripts create a button on an Excel worksheet?
No. Office Scripts can work with worksheets, ranges, tables, and other supported workbook objects, but they cannot currently create worksheet buttons or assign an Office Script to a new button through code.
How can I put the same Office Script button on every new worksheet?
Create one worksheet manually with the button already added from the Automate tab. In your Office Script, use workbook.getWorksheet("TemplateName").copy() to duplicate that prepared worksheet.
Will a copied Excel worksheet keep its existing Office Script button?
A copied template worksheet is the recommended workaround because it preserves the prepared worksheet setup. Test the copied sheet in your workbook to ensure the button continues to run the expected script.
Can VBA create buttons in Excel when Office Scripts cannot?
In desktop Excel, VBA can create certain worksheet controls and assign macros, subject to the workbook's macro settings and the available control types. VBA and Office Scripts use different automation models.
Where do I add an Office Script button manually in Excel?
In Excel for the web, open the Automate tab, select the Office Script you want to use, and choose Add button to place a button on the current worksheet.




