You have full access to the Excel COM Object Model from within your Excel-DNA add-in. One important step is that you have to get hold of the correct Application
root object for the Excel instance that is hosting your add-in. (Just calling new Application()
might get hold of another Excel instance.) To get hold of the Application
object you call ExcelDnaUtil.Application
- that return the COM object.
From there you can use the dynamic
support in C# to talk to the object model. But better is to reference the Interop assemblies, giving you IntelliSense and early-binding.
A convenient way of referencing a set of interop assemblies (corresponding to the Excel 2010 object model) is to install the ExcelDna.Interop
package from NuGet. With the 'Embed Interop Types' feature in .NET 4 (which is set true
by default), you need not redistribute anything special and your code will be compatible with all Excel versions, as long as the object model parts you use are supported there.
As an entry point into running the COM code, you can make a macro, shortcut ribbon or context menu. From the object model you could also hook COM events.
A simple example with detailed instructions for making a Ribbon button that then runs some COM code is available on GitHub.
Note that the VSTO wrappers on top of the COM object model (everything in a Microsoft.Office.Tools.Excel
namespace) are not compatible with your Excel-DNA add-in, so you'd have to implement that functionality yourself based on the native COM object model (the types in the Microsoft.Office.Interop.Excel
namespace.)