office-jsoffice-addinsexcel-addinscustom-functions-excelexcel-web-addins

Information Section in Excel Custom Function


In excel function we have a by default help section for any function like SUM, COUNT. I have created excel custom function but in my function I am not able to add the help section for that. Default Function

I have implemented the following code for excel custom function.

/**
 * Multiply By 10.
 * @customfunction
 * @param count First number.
 * @returns {number} The multiply by ten.
 */
async function count(count) {
  return count * 10;
}

How can I call the help section on the click of function in the excel custom function.


Solution

  • The following steps may achieve your request.

    step 1. Register an onSingleClicked event handler on your worksheet in your Custom Functions add-in.

    async function registerClickHandler() {
      await Excel.run(async (context) => {
        const sheet = context.workbook.worksheets.getActiveWorksheet();
        sheet.onSingleClicked.add((event) => {
          return Excel.run((context) => {
            console.log(`Click detected at ${event.address}`);
    
            return context.sync();
          });
        });
    
        console.log("The worksheet click handler is registered.");
    
        await context.sync();
      });
    }
    

    step 2. Use Excel.Range.formulas property to get the function name when the event is detected.

        const cell = sheet.getCell(row, col);
        cell.load("formulas");
        await context.sync();
        console.log(`Cell.formula is "${cell.formulas}"`);
    

    step 3. jump to the corresponding help page(prepared by yourself) URL in your add-in's task pane.

    Another way is to provide an overall help page link in your add-in's task pane to let the user learn how to use your Custom Functions directly when they click the link, instead of when they click the formula. I'll suggest this way.

    Moreover, currently, the Custom Functions doesn't support showing the dialog. If you are requesting this feature, I'd recommend going to Microsoft 365 Developer Platform, see if this feature has already been requested, or request a new feature.