You are approaching a problem from the wrong direction. When you click the button, you donβt want to create a new add-in, what you really need is to access the add-in instance that VSTO creates for you when you start Excel, which is accessible through Globals.ThisAddIn ,
Change your code in the Form to the following:
private void btnUploadTestCases_Click(object sender, EventArgs e) { var addIn = Globals.ThisAddIn; addIn.RefreshExcelData(); }
... and he must work in charm.
As the saying goes, is there a good reason for this method to be on ThisAddIn? In general, ThisAddIn should be used to connect and reset the add-in when Excel starts / shuts down, and I would recommend putting in as little logic as possible.
source share