Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,986 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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);
}