title: Create an Excel Macro definition in C#
body: <p>I want to create a Function in my C# code, which can be called from VB as if it were a Macro.</p>
  
  <p>i.e. the VB code should be able to do:</p>
  
  <pre><code>sub vb_method
      csharp_method("some_parameters")
  end sub
  </code></pre>
  
  <p>and have that call my C# method:</p>
  
  <pre><code>public object csharp_method(String parameter) {
      ...
  }
  </code></pre>
  
  <p>I know this can be done in C++:</p>
  
  <pre><code>LPXLOPER retval;
  LPXLOPER module;  // = something
  LPXLOPER parameters[] = { module,
                           "cpp_function", "parameter_type_info",
                           "MacroName", "text",
                           2,
                           ... };
  Excel4v(xlfRegister, retval, parameter_count, parameters);
  </code></pre>
  
  <p>This registers my <code>cpp_function</code> so that it can be called by the name <code>MacroName</code>.  But it's using XLOPER stuff (which is a headache), and it's in C++.</p>
  
  <p>The magic <code>2</code> tells Excel to use my function as a macro.  Then my c++ code can be called from VB, or using <code>ExecuteExcel4Macro</code>.  I can also use this to register User-Defined Functions (UDF) - just use a magic <code>1</code> instead.  (more details about xlfRegister here:  <a href="http://msdn.microsoft.com/en-us/library/bb687900.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb687900.aspx</a> )</p>
  
  <p>C# makes it very easy to create UDFs, but I need a way to register my functions as macros instead of formulas.</p>
  
  <p>So how can I have a Macro call my C# code?</p>