Questions tagged [office-scripts]

Office Scripts is a feature that allows you to automate tasks in Microsoft Office using TypeScript. Currently, this feature is only supported in Excel. Use this tag to ask programming questions about Office Scripts, and consider adding the related tags Excel and TypeScript where relevant.

Office Scripts is a feature that allows you to automate tasks in Microsoft Office using TypeScript.

Currently, this feature is only supported in Excel.

Office Scripts can be created either by using a macro recorder, or by manually writing the script.

Office Scripts contrast themselves from VBA by being usable in Office Online, being primarily asynchronous (while VBA is nearly always synchronous), and lacking support for events. Office Scripts also cannot work with local files and programs.

The documentation is available here: https://learn.microsoft.com/en-us/office/dev/scripts/

Office Scripts use a subset of the Excel JavaScript API, the documentation for that can be found here: https://learn.microsoft.com/en-us/office/dev/add-ins/reference/overview/excel-add-ins-reference-overview

314 questions
3
votes
2 answers

ExcelScript: getNumberFormat from column A to C

I need to get the NumberFormat from an excel file (appr. 3000 lines) and I wrote a simple Script which copy it from column A to column C each row by row. I tried to use this script with Power Automate after 10 minutes. I already set the timeout on…
3
votes
2 answers

Fetch error on Office Script (Excel on web)

I am trying to call an external API from an Excel on web. However, I am stuck on trying to get the result from the fetch call. I am even using the Office doc example to make sure From an Excel, click on Automate to create a new script async function…
Miguel Guardo
  • 853
  • 1
  • 9
  • 17
3
votes
0 answers

Why do i get a "BadGateway" Error When Running the Excel Online "Run Script" Action in PowerAutomate?

I have recently being using the new Office Scripts function on Excel Online, and when i have tried to connect this with flow and try to run the script, it results in a BadGateway Error, after it retries twice BadGateway Can anyone help with this? { …
johnk3
  • 31
  • 3
3
votes
1 answer

How to write an office script that executes a predefined query to load data into a sheet?

I have an excel workbook in which I have selected the "Get Data" option to import from an OData Feed. Using a public odata feed for testing. This defines a query in excel that can be edited/viewed through Power Query Editor. I am new to office…
Andy Dufresne
  • 6,022
  • 7
  • 63
  • 113
2
votes
2 answers

Office Scripts - Merge Cell

Is there a code for repetitive merging. Like for example I want to merge A1:B1, then again A2:B2, then A3:B3 and so forth. It goes a long way up to 500th cell A500:B500? I am familiar with this code: function main(workbook: ExcelScript.Workbook)…
Randy Mata
  • 23
  • 4
2
votes
0 answers

Need help getting OpenAI API working in Excel using Office Script

I'm trying to get the OpenAI API working in Excel using Office Script (TypeScript), but I seem to be running into some trouble. When I run the script, it doesn't give any output. Any suggestions? In the Excel workbook, I have the following…
2
votes
0 answers

How can I mark part of the text in a cell in bold?

With VBA you can mark a part of the text bold like this: Sub Makro1() ActiveCell.FormulaR1C1 = "test test test test test" With ActiveCell.Characters(Start:=1, Length:=6).Font .FontStyle = "Standard" End With With…
2
votes
2 answers

Excel Script keeps giving error "Range merge: You cannot perform the requested operation."

Ï'm writing an Excel Script. Given a selected cell, it should: Insert a row below the selected cell (this works) For all cells of the inserted row which are in a column left of the selected cell, merge it with the cell above it (which is on the…
2
votes
1 answer

Office script writing last element of array to entire range

I am trying to write the converted values of a selected range to the adjacent column of cells. I am able to get the values written to the cells, however, it only prints out the value of the last item in the range to all of the cells. I've included…
2
votes
1 answer

Office script keep returning failed to fetch error. The code works in google sheet and pythong

Trying to run the following code in excel office script, but it keep returning the "Maximum call stack size exceeded" error async function main(workbook: ExcelScript.Workbook) { // Your code here const cuslocation = "New York" …
2
votes
1 answer

Replace values on multiple worksheets using Office Scripts

This script is currently taking 45 sec to run, Any thoughts on enhancing the performance on this? function main(workbook: ExcelScript.Workbook) { try { const sheets = workbook.getWorksheets(); for (let sheet of sheets) { const breakCol =…
2
votes
3 answers

Embed Excel scripts into the .XLSX file?

I know that Excel TypeScript scripts are saved to your OneDrive, and that you can share that script with other members of your organization (though it seems you can only share it with everybody, not specific people). Is there a way to embed the…
Josh Silveous
  • 479
  • 2
  • 6
  • 16
2
votes
1 answer

How to add data table in chart from office script

I create the online chart from my pivot table.that pivot table is source my chart.but i can't get chart data table in office script I need to add "chart data table" from office script code Here is my code. I don't have any idea how to add that data…
2
votes
1 answer

Iterator Only Repeating Its Max Potential Value in Nested For Loop (Office Scripts)

I'm using Power Automate & Office Scripts to build a way to do batch creates in Excel. Essentially a way to send an array of values to a script in Excel that then updates an Excel table with all the values in the array. Office Scripts use the…
2
votes
1 answer

Excel Office Scripts - Replace "blank cells" with the text "null"

I'm trying to replace blank cells in column B (column name= Status) with the text "null". I have two different approaches that get me halfway there, however I can't figure out how to fully solution this. Any help would be greatly appreciated Here's…
ckatz
  • 23
  • 8
1
2
3
20 21