This question is from one of my customers who is developing an excel web add-in, they would like to detect whether the event is trigger by end-user or trigger by the code.
They have registered a Worksheet.onChanged event handler.
They would like to ignore the onChanged event change that triggers by their code themselves. and focus on Processing the event handler should only be done when the user changed the values.
Scenario: add-in listens to the sheetChange event. add-in user to enter values into the crosstabs, which the add-in will push to the server. However, add-in API can also do some modification on the crosstabs, for example, the add-in can enable the user single click and drill down to get more data, their API logic will fetch data from the service and write to the crosstabs. however, the sheetChanged event will be triggered as well.
The solutions that the customer has been tried:
First try: We tried to deregister the event handler before changing the values. We then registered again after having the values changed. This did not work as the deregistration is async and we were not able to await the deregistration.
Second try: context.runtime.enableEvents = false This is not possible as there are other events we are still interested in.
Current try: We store the address of the changed range before changing the values. In the onChanged handler, we compare the address. If the same we do not do the logic. After that, we delete the storage of the address again.
I also have tried to use a global flag and checking for that in the event handler, it doesn't work. here is my gist: https://gist.github.com/lumine2008/2b51d94d20cdca9ac9a0e97029dfd95c