Discussion:
Passing arrays from Excel (VBA) to C# using COM interop
(too old to reply)
jlea
2008-02-26 23:53:28 UTC
Permalink
Hi - I'm using VS2005/Excel 2007 and can pass scalars from Excel to a C#
class exposed with [ClassInterface(ClassInterfaceType.AutoDual)] and setting
the assembly to Register for COM Interop and all works fine until I try to
pass an integer array from VBA to C#: I initially get "Function or interface
marked as restricted, or the function uses an Automation type not supported
in VB" and when I add "ref" to the C# function I get "Type mismatch: array
or user defined type expected".

Does anyone know what the trick to use to allow passing arrays (and ideally
other data types, objects, and returning various data types to Excel) from
Excel to a C# assembly?

Thanks.

Jon.
Gidders
2008-07-03 23:36:11 UTC
Permalink
Check the type of the array elements. You can look up what type of
parameter is expected in the vba object explorer.

An int in c# is a Long in VBA, so you may need to change your array in VBA:

Dim MyArray(10) As Long

url:http://www.ureader.com/msg/1032244.aspx

Loading...