0

A Refresh button/method in an Excel Add-In needs to be invoked via an external winform application. Here is where I am up to:

private Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
public FormMain()
{
InitializeComponent();
RefreshExcelSheet(@C:\a.xls");
} 

private bool RefreshExcelSheet(string path)
        {
           using (var wb = excel.Workbooks.Open(path).WithComCleanup())

How do I click the Refresh button or simply invoke its event?

I was looking at these articles but they are using VBA, I want a Winform app to open the spreadsheets and click the button:
Accessing a VSTO application-addin types from VBA (Excel)
Expose VSTO functionality to VBA w/o local admin

Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321

2 Answers2

2

The simplest way to solve this problem is to just expose the existing custom .net method as a COM method by making is a com callable wrapper object (CCW). VSTO provides you with a simple method to expose the COM Automation server.

http://blogs.msdn.com/b/andreww/archive/2007/01/15/vsto-add-ins-comaddins-and-requestcomaddinautomationservice.aspx

EDIT BY OP: Andrew Whitechapel has updated the article, but I cannot get it to work. Even with StandardOleMarshalObject and Register for COM interop I still get the same error message as detailed in this article: http://blogs.msdn.com/b/andreww/archive/2008/08/11/why-your-comaddin-object-should-derive-from-standardolemarshalobject.asp

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
Anonymous Type
  • 3,051
  • 2
  • 27
  • 45
0

Anonymous Type's suggestion is surely the best approach if you can extend the Excel add-in.

If it's a 3rd party tool it's still possible to use the ribbon's IAccessible interface to invoke the ribbon button. However, you can expect this to be much more complicated. In case you have to follow that path here are some links to get you started:

Community
  • 1
  • 1
Paul B.
  • 2,394
  • 27
  • 47