Using VSTO or some related technology, is it possible to programmatically embed a button in a cell of an Excel worksheet, and configure it to call a C# function when it is click
Here is the code which works for me in VSTO Add-in (modified version of Mathias's answer):
using Excel = Microsoft.Office.Interop.Excel;
using ExcelTools = Microsoft.Office.Tools.Excel;
public void AddButtonToWorksheet()
{
Excel.Worksheet worksheet = (Excel.Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;
ExcelTools.Worksheet vstoSheet = Globals.Factory.GetVstoObject(worksheet);
Button button = new Button();
button.Text = "Dynamic Button!";
vstoSheet.Controls.AddControl(
button, 50, 50, 100, 50, "TestButton");
}