0

I have created a VSTO Excel add-in. This add-in is programmed in C# and provides functionality which shall be consumed by VBA (see Walkthrough: Call code in a VSTO Add-in from VBA). This is working fine. In general, the functions I call from VBA take a little longer to execute, so I thought I would like to have VBA callbacks which I can pass when calling the VSTO functions. So far, I have tried two approaches which both do not work:

  1. The Timer callback approach using the AddressOf operator. The C# function takes an IntPtrand converts it using Marshal.GetDelegateForFunctionPointer. I can get the address but when I call the VSTO-function in VBA, I get the error Class does not support Automation or does not support expected interface. I have read that it definitely does not work for callbacks within VBA, but it obviously does not work VBA/VSTO either. It seems that this approach only works for native callback-callers.
  2. The Interface approach. I have only found this for the combination VB/.NET and I do not know how make the interface declared in VSTO known to VBA, like Implements IVBCallBack (with IVBCallBack coming from VSTO) is used in the accepted solution for the given question. I added the [ComVisible(true)] attribute to the interface on the VSTO side but do not know how to reference the interface in VBA.

I would like to avoid calling VBA from VSTO using a known function on the VBA side, because then I would be bound to one single 'callback'-functionality. Is there a way to properly implement callbacks between VBA and VSTO?

HJP
  • 67
  • 1
  • 6

0 Answers0