I can find numerous resources that explain how to dynamically add a button to a sheet in a Excel VSTO Add-in project. Something like this should work:
Private Sub AddButtonToSheet(ByVal sheet As Excel.Worksheet)
' Add a button to the sheet
Dim vstoSheet As Microsoft.Office.Tools.Excel.Worksheet = Globals.Factory.GetVstoObject(sheet)
Dim button As Microsoft.Office.Tools.Excel.Controls.Button = vstoSheet.Controls.AddButton(50, 50, 100, 30, "myButton")
' Set button properties
button.Text = "Click Me"
AddHandler button.Click, AddressOf Button_Click
End Sub
Unfortunately, I’m not able to get the the call to Globals.Factory.GetVstoObject(sheet)
to work in a VSTO Workbook project (it returns Nothing
).
Is it possible to create buttons at runtime using VSTO Workbooks and if so, how?