0

I wrote I simple Excel Script which works online pretty well, but if I use the same Script with Power Automate I get an error.

Here ist the Script:

function main(workbook: ExcelScript.Workbook)
{
  let sheet = workbook.getActiveWorksheet();

  let range = sheet.getUsedRange();
  let rows = range.getRowCount();
  let cols = range.getColumnCount();
  
  for (let row = 2; row <= rows; row++) {
  
  }  
}

I am getting the message: Runtime error Line 5: Cannot read property 'getRowCount' of undefined

Does anybody know why this message occurs only with Power Automate and how to solve it?

Ethan
  • 808
  • 3
  • 21

1 Answers1

0

I’ve been told to stay away from using “workbook.getActiveWorksheet” and ActiveCell when using Power Automate. Instead you can use

workbook.getWorksheets()[0]

Or

workbook.getWorksheet(“Sheet1”)

If that isn’t the problem, then maybe you can try to get the UsedRange in a better way.

If you use

sheet.getUsedRange(true)

getUsedRange has an optional Boolean parameter to get values only.

getUsedRange documentation

Ethan
  • 808
  • 3
  • 21