0
votes

I am working on an Excel Add in using Excel Javascript API.

https://docs.microsoft.com/en-us/office/dev/add-ins/reference/overview/excel-add-ins-reference-overview

Is there a way to switch focus from taskpane to the sheet? Now if user clicks on an element on the taskpane she cannot use the the arrow keys to navigate the excel sheet until she has clicked the sheet area again with the mouse.

Use case
It would be nice to have a button on the taskpane that would paste text to a certain range on the sheet and would also move the focus to the sheet, so the user could start navigating with arrow keys immediately after pressing the button.

Pasting the text to the range and setting the selection are working fine, but I cannot find a way to move focus from the taskpane to the sheet with JS API.

Any help is very much appreciated,
Thank you!

1

1 Answers

0
votes

The best what you could do is to try to Set the active worksheet:

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});

If this isn't what you are looking for, I'd suggest you to file a feature request here: https://aka.ms/M365dev-suggestions .