Excel cell binding events not triggering after reopen of the workbook
Office.onReady((info) => { // Check that we loaded into Excel if (info.host === Office.HostType.Excel)
{ loadBinding(); }});
function loadBinding() {
Excel.run(async (context) => {
// sample code goes here
const cellAddressRange = context.workbook.getSelectedRange();
cellAddressRange.load("address");
await context.sync();
console.log(cellAddressRange.address);
const bindingId = "binding_" + Math.random().toString(36).substr(2, 9);
const binding = context.workbook.bindings.add(cellAddressRange,Excel.BindingType.range,bindingId);
binding.onDataChanged.add(async (eventArgs) =>
{
try {
console.log("cell value updated event handler called.");
const range = eventArgs.binding.getRange();
console.log(range);
range.load("address,values");
await context.sync();
console.log(range.address, range.values[0][0]);
}
catch (error)
{ errorHandlerFunction(error);}});
await context.sync();
}).catch(errorHandlerFunction);}
function errorHandlerFunction(error)
{
console.error(error);
}