Hi Homero,
The ExcelCommand allows your add-in to define macros that run from a
menu or ribbon button.
The (public static) method method must have no parameters and return
type 'void'.
You can also type the macro name into the 'Run Macro' dialog box - it
won't be listed there but the Rub button will become enabled if you
type a valid macro name, or you can execute it from VBA using
Application.Run.
The easiest way to get a menu for your macro is to set some values in
the [ExcelCommand] attribute. Under Excel 2007 this gives you a menu
under the 'Add-Ins' tab. You can also add a custom ribbon to your
Excel-Dna Add-In, or build a whole CommandBar hierarchy, but that's a
bit more advanced.
So your method might start with:
[ExcelCommand(MenuName="Range Tools", MenuText="Square Selection")]
public static void SquareRange()
{...}
There is a nice example of how to dump data into Excel using the Excel-
Dna and the C API style (XlCall.xxxx) in my answer here:
http://stackoverflow.com/questions/3840270/fastest-way-to-interface-between-live-unsaved-excel-data-and-c-objects
In this example I read a range, process and write to a new sheet; it
might give you a good start.
Another approach to implement your method is to use the COM automation
interface to talk to Excel. For this you'll need to get hold of the
right Application object - call
ExcelDna.Integration.ExcelDnaUtil.Application to get the right object.
From there you are talking to the same COM object model as you would
from VBA. To interact with the COM object model you can either
reference the PIA in your assembly, use late-binding through
reflection using Invoke, or use the 'dynamic' type in C# 4. Each
method has its pros and cons.
Hope this gets you started.
Cheers,
Govert