Excel Change Handler

${ C# library to detect and process changes made to Excel worksheets }
2020-05-11

/* project archived */

This library enables data changes in an Excel workbook to be detected and handled in a VSTO addin. The initial use-case was to automatically colour and log any changes to an Excel workbook.

This came from a job where people working with certain (large) workbooks were advised to manually update the background colour of any cells they changed - this was then used to peer-review those changes.

Obviously, since it was manual, people didn’t always do that! So this project was a piece of a larger set of automations my team built on top of Excel to automate that process.


This functionality is more complicated that it should be because the Excel event API for cell changes only includes the new data 🙄

Meaning that the data the cell contained before it was changed is no longer available when the event is triggered. To work around this, the library remembers the data of each cell that is selected (before the cell is changed) and then compares its own memory against the new data.

This is why the library has before change and after change handler functions. The before function should be hooked into events that fire before a change is made to store the cell data that is about to be changed.

  • For example selection changed and sheet activated events

The after event should be hooked into events that fire after a cell is changed.

  • For example, the cell changed event

Once the after change event handler is called, it will check the new data against the previous state it has in memory and, if the data has changed, invoke all the change handlers which have been registered.


It was a fun project! The code is still available, but this project has been abandoned.