Passing Worksheet as an argument crashes.

Jul 15, 2013 at 9:50 PM
<DnaLibrary RuntimeVersion="v4.0" Name="TestDna" Language="C#">
<Reference Path="System.Windows.Forms.dll" />
<![CDATA[
public class WorksheetParamTest
{
    public static void HelloWorld( object o )
    { System.Windows.Forms.MessageBox.Show(o.GetType().ToString()); }
}
]]>

<!--  DEMO VBA CODE
Sub Macro1()
    Application.Run "HelloWorld", ActiveSheet.Name ' this works
    Application.Run "HelloWorld", ActiveSheet ' this crashes.  Why?
End Sub
-->

</DnaLibrary>
Coordinator
Jul 15, 2013 at 9:56 PM
Hi,

Yes - I would not expect that to work.
Excel-DNA integrates with Excel through the C API which only supports a limited set of argument types. You can't directly pass COM objects through the C API.

Excel-DNA does have some support for making classes from your add-in directly available as COM classes to VBA, but that's tricky to set up, so quite an advanced feature. For a start it's best to try to get by with the basic types.

-Govert