IIRC you need to pass arrays by reference.
Try declaring your method as
public class MyClass { public void Method1([In] ref UserDefinedClass[] Parameters) { ... } ... }
If you do not want to pollute your class with ref parameters for .NET clients, you can define the ComVisible interface that will be used by COM clients and implement it explicitly:
[ComVisible(true)] public interface IMyClass { void Method1([In] ref UserDefinedClass[] Parameters) { ... } ... } public class MyClass : IMyClass { void IMyClass.Method1(ref UserDefinedClass[] Parameters) { this.Method1(Parameters); } public Method1(UserDefinedClass[] Parameters) { ... } }
** In response to the comment ** If you want to expose the collection instead of an array in VBA, you just need to expose an enumerator and any other methods that you want the VBA code to call (for example, "Add", "Delete", "Insert "," Clear ", ...), for example.
[ComVisible] public interface IUserDefinedClassCollection { IEnumerator GetEnumerator(); int Count { get; }; IUserDefinedClass this[int index] { get; } int Add(IUserDefinedClass item);
Then you can use it as usual in VBA:
Dim objUserDefinedClasses As UserDefinedClassCollection ... objUserDefinedClasses.Add objUserDefinedClass ... For nIndex = 0 To objUserDefinedClasses.Count Next nIndex
Joe
source share