0

After long hours of investigation on exposing C# property that accepts a reference type to VBA, I concluded that it was not possible. In brief, a C# property that is of type double[] or even an object cannot be consumed in VBA like this:

' Compile Error: Function or interface marked as restricted,
' or the function uses an Automation type not supported in Visual Basic
oComExposedEarlyBinding.ObjectArray = VBArray

' Run-time error 424: Object required
oComExposedEarlyBinding.PlainObject = VBArray

Or for more details: C# property exposed to VBA (COM) : Run-time error '424': Object required

I would like to know if C++/CLI would support such an option? i.e. Allowing a reference-type property to be exposed to VBA so that a syntax like the above is valid.

N.B. You can achieve this by using late binding, but losing the intellisense is not an option.

Community
  • 1
  • 1
Adam
  • 3,872
  • 6
  • 36
  • 66

1 Answers1

0

This is possible in C++/CLI because the property in C++/CLI is composed of two functions a get and a set and in C++/CLI you CAN have a reference function (versus a pointer one).

The same property that is exposed in a similar way in C# won't work.

This property is exposed as expected to COM and there will be no issue setting or getting in VBA:

private:
    Object ^_myProp;
public:
property Object %MyProp { 
    virtual Object %get() 
    {
        return *_myProp;
    }
    virtual void set(Object %value) 
    {
        _myProp = %value;
    }
};
Adam
  • 3,872
  • 6
  • 36
  • 66