Excel cell binding events not triggering after reopen of the workbook

Senthilnathan Vaduganathan 0 Reputation points Microsoft Vendor
2024-10-18T00:46:38.26+00:00

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);

} 
Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,955 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
996 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.