0

I am working on a Excel Web Add-In using Office.js. I added onSelectionChange event for a workbook and later trying to remove it, but this event still works. Here you can find an example that I created with ScriptLab, that shows that event can not be removed: https://gist.github.com/shss1985/afd1c00484acfec33740cdbcda3f78b5

Is there a way to remove it correctly?

Thanks.

Sergey
  • 45
  • 5

2 Answers2

1

To remove the handler you have to use the same RequestContext as was used to add it. For details about how you do this, see Remove an event handler.

Rick Kirkham
  • 9,038
  • 1
  • 14
  • 32
  • 2
    No Code :( An line of code is worth 1k words. – FreeSoftwareServers Apr 16 '22 at 02:20
  • hey Rick, don't think I don't appreciate all your answers, I see you everywhere, just being unbiased! I actually figured out the issue I am having w/ removing events (its due to the `same context` clause). I posted a similar question on how to check for events if you have a moment --> https://stackoverflow.com/questions/71904238/check-for-existing-event-handlers-on-worksheet-office-js-excel – FreeSoftwareServers Apr 17 '22 at 18:03
-1

Removing them looks like this --> But, must be called in the same context so my issue is really that I need to be able to check if they are already registered, as this remove doesn't remove previously setup event handlers when my page refreshes and gets new context

Note: the var lines actually register the event, so you can comment out the remove to test.

var var_onActivated = ws.onActivated.add(Client_WOs_Do_onActivated);
var var_onDeactivated = ws.onDeactivated.add(Client_WOs_onDeactivated);

await var_onActivated.remove();
await var_onDeactivated.remove();
FreeSoftwareServers
  • 2,271
  • 1
  • 33
  • 57