0

I modified an Excel ScriptLab function to remove duplicates and I run it as a button from the Ribbon.

async function RemoveDuplicates() {
  await Excel.run(async (context) => {    
    const sheet = context.workbook.worksheets.getActiveWorksheet();
    var selectedRange = context.workbook.getSelectedRange();
    var firstCell = selectedRange.getCell(0, 0);
    var surroundingRegion = selectedRange.getSurroundingRegion();

    firstCell.load('columnIndex');
    surroundingRegion.load('address');

    await context.sync();
    var columnIndex = firstCell.columnIndex;
    
    const deleteResult = surroundingRegion.removeDuplicates([columnIndex], true);
    deleteResult.load();
  });
}

It works well. It finished in a fraction of the second, but I noticed that this, and any other function I have, displays in the bottom-right corner a message that stays there until I run another function. And then the message from the next function stays there.

enter image description here

Is this normal, or should there be a code to end this function?

Thanks

Tomasz Decker
  • 114
  • 2
  • 14

1 Answers1

1

You might need to pass an Office.AddinCommands.Event parameter to removeDuplicates and then call event.completed() at the end of the function. For an example, see Create add-in commands and FunctionFile.

Rick Kirkham
  • 9,038
  • 1
  • 14
  • 32
  • I used the code you suggested and it works. Thank you. But this code is for JS, and TS takes also type. I tried async function highlightNonEnglish(event: Event), but it returns error, so I used this code: async function highlightNonEnglish(event: any). This works weell. Is this a good way in this case? – Tomasz Decker Apr 21 '21 at 09:38
  • I believe the data type for the parameter is https://learn.microsoft.com/en-us/javascript/api/office/office.addincommands.event?view=common-js – Rick Kirkham Apr 21 '21 at 20:33
  • I added this link to the original answer. – Rick Kirkham Apr 23 '21 at 01:44