0
votes

I am using VSTO / .NET4.0 to create an Excel addin. I would like to embed controls (buttons and comboboxes) into a worksheet. I use the code below, but once I save the workbook, close it and reopen it, the button has changed into a flat image which has no functionality. What am I doing wrong? Any help would be greatly appreciated!

System.Windows.Forms.Button b = new System.Windows.Forms.Button();
b.Text = "Run";
sheet.Controls.AddControl(b, (sheet.Cells[rowidx, colidx] as Range),"buttonName");
b.Click += this.runSimulation;
1

1 Answers

0
votes

There are 2 types of VSTO solutions: add-in, and document customization. You can add controls to a sheet dynamically with add-ins, however, the controls will be gone once you close and re-open the document. If you want your worksheet to have "durable" custom controls, what you are after is probably a document customization: you can develop and design your document with the controls, and unlike the add-in, the code is "attached" to the Workbook.