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
2
votes
1 answer

Copy table from one sheet to another

I would like to copy the whole table from one sheet(inputSheet) to another(outputSheet), and then, keep copying & adding more tables to the same ouputSheet Here are some things I have tried: function main(workbook: ExcelScript.Workbook) { const…
rrh
  • 808
  • 7
  • 12
2
votes
1 answer

Protect Worksheet in Office Scripts with Options

How can I protect a worksheet but allow the user to format the columns in Office Scripts? I have tried a few things but haven't had any success. function main(workbook: ExcelScript.Workbook) { let sheet = workbook.getWorksheet("By Item"); …
Ethan
  • 808
  • 3
  • 21
2
votes
1 answer

Refresh All Queries and Connections of an Excel Workbook (Excel Online) using Office Scripts and Power Automate

I started using the new Office Scripts in Excel on the web. I was wondering if anyone knows if it´s possible to Refresh the Queries and Connections of an Excel Workbook saved on SharePoint Online. I would like to run the script utilizing a Scheduled…
SLazz
  • 21
  • 1
  • 5
2
votes
2 answers

How to handle event on data change in excel sheet to refresh all pivot tables?

I have a VBA code applied to Worksheet and its change. So whenever there is new entry or deletion (any change) in the sheet, it refresh all the pivot tables attached to it - Private Sub Worksheet_Change(ByVal Target As…
2
votes
4 answers

Can I use both Office Script and VBA macros in the same workbook?

I have VBA macros enabled on workbooks currently used on Desktop Excel. However, my company has moved our workbooks from network drive storage onto Microsoft Teams so many people are now using Excel for Web to access them, upon which VBA does not…
HelenT
  • 41
  • 3
  • 7
2
votes
2 answers

Office script, Delete range name ignored, no errors

I just created this tiny Office script: async function main(context: Excel.RequestContext) { context.workbook.names.getItem("Newname").delete; } The range name 'Newname' exists in the current workbook, the code runs without error but the name is…
jkpieterse
  • 2,727
  • 1
  • 9
  • 18
1
vote
1 answer

Excelscript: Copying information for duplicate rows

I usually use VBA in Excel to automate laborious tasks like cleaning up a table of data, but I want to try out Excel Scripts. Being less familiar with JavaScript, I thought I'd try ChatGPT to do the heavy lifting. I think it'll work apart from a…
Dominic
  • 69
  • 1
  • 7
1
vote
2 answers

Select specific worksheets in office script

there are sheets in my workbook that can either be titled "PL -Flat" or can be titled "FLAT" this is the code that I have been using for the PL -Flat sheets, but I would prefer to use an if statement so I could select either of these sheets because…
1
vote
1 answer

Office Script that replaces blank cells with "null" text, ignoring merged cells

I am trying to write an Office Script that replaces blank cells with "null" text that I can run in Excel Online. The script I have right now is replacing merged cells with "null". I would like to write it so that if a cell is blank and not merged,…
Austin
  • 11
  • 3
1
vote
1 answer

Adding Image from URL to specific Cell using Office script

I am trying to add a QR Code on specific Cell using office script, The following code works fine but, I am not able to figure out how to specify the position(cell G1), I want that QR Code top left corner to start at Cell "G1". async function…
1
vote
0 answers

Create 1 ReturnObject from 2 JSON object arrays with Typescript

I'm trying to create a JSON with an Excel office script, to use this JSON in a Microsoft Power Automate flow to create Item master data . My problem is that I don't get the message header and the Item details into 1 ReturnObject. I'm a beginner in…
Roop
  • 11
  • 1
1
vote
1 answer

Office Scripts Sorting a Pivot Table

I have an Office Script that creates a Pivot Table. The last thing I would like to do is sort the pivot table on the same column values I filtered. Scripts doesn't record this action and I am not finding any examples. I do not understand how to…
JSP
  • 35
  • 5
1
vote
1 answer

Where is the "Settings" for connecting Office Scripts to VS Code Web?

Per, https://learn.microsoft.com/en-us/office/dev/scripts/develop/vscode-for-scripts?source=recommendations#connect-visual-studio-code-to-office-scripts, I should "Under the More options (…) menu, select Editor settings.", but I don't see the…
swv
  • 691
  • 1
  • 12
  • 28
1
vote
0 answers

Excel office script - Delete row (except first 2 columns) after row has been copied to a new tab

I have a script that will move a row to another table if a certain cell within that row is filled. The script then deletes the entire row. I would like for this to continue but instead of deleting the entire row it would be great if it deleted the…
1
vote
1 answer

Excel office script - copy a row to a new tab if cell is NOT empty

I have created a script that will move an entire row to another tab on the worksheet if certain text is entered into a selected cell. I want to be able to do this if the cell is not empty rather than having certain text and I would like the row to…
Eti
  • 23
  • 4
1 2
3
20 21