How do I create a variable that gets the address from my excel sheet? - SCRIPT LAB

428 Views Asked by At

This is probably a simple task, however I cannot figure out how to get data from a cell in this version. I am very familiar with the way that vba would look up the value in a cell -- range('a1').value -- in script lab it seems like it is a completely different naming convention.

Here is what I want to do:

var targetaddress = /* range value of a1 */
1

There are 1 best solutions below

0
On

The main thing is to remember about await context.sync(); in Script Lab editor, which stands for Application.DoEvents and that Excel cells counting starts at 0 in TypeScript.

async function run() {
  await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    var targetaddress = sheet.getRange("A1");
    targetaddress.load("values");

    await context.sync();

    console.log(targetaddress.values[0][0]);
  });
}

Also You have to pass coordinates [0][0] of the cell of your range - targetaddress