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" />
public class WorksheetParamTest
    public static void HelloWorld( object o )
    { System.Windows.Forms.MessageBox.Show(o.GetType().ToString()); }

Sub Macro1()
    Application.Run "HelloWorld", ActiveSheet.Name ' this works
    Application.Run "HelloWorld", ActiveSheet ' this crashes.  Why?
End Sub

Jul 15, 2013 at 9:56 PM

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.