See the question and my original answer on StackOverflow

You can't use generics with COM, you can't use static functions, etc. Here is a similar code that should work:


Sub main()
    Dim arr(1000000) As Variant

    For i = 0 To UBound(arr)
        arr(i) = Int((1000000 + 1) * Rnd)
    Next i

    Set ExpandExcel = CreateObject("ExpandExcelStandard") // I used late binding but early is fine too
    resultArr = ExpandExcel.RemoveDuplicates(arr)
End Sub


[ProgId("ExpandExcelStandard")] // because I wanted late binding, I declared a progid
public class ExpandExcelStandard
    // .NET object (w/o any Marshal spec) is passed as an automation Variant
    public object[] RemoveDuplicates(object[] arr) => new HashSet<object>(arr).ToArray();