Is it possible to hit a WinForms "Button" from an Excel spreadsheet (VBA)?
The traders are lazy and they don't want to switch applications to hit buttons. When they hit the button in Excel, it sh开发者_StackOverflow社区ould be the same as hitting another button in my WinForms app (which pops up a dialog box). Doable?
Yes.
You need to put your functionality into a [ComVisible(true)]
DLL and add a reference to it in VBA.
Alternatively, you can write an Excel addin in C#.
- Write a COM server that communicates with the WinForms app using the inter-process communication mechanism of your choice
- Add an Excel button to the sheet
- Write some VBA to call the COM server
It would be nice to expose a COM object directly from the WinForms app in such a way that you can call it through the VBA GetObject
function. However, I can't see an obvious way to expose an object to the COM running object table from .NET.
精彩评论