Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Additional methods in a class module implementing an interface in VBA

I write a VBA macro for Microsoft Excel 2010.

Some of the modules in my project would really cry out for subclasses, but I already understood that inheritance is not supported.

Knowing that, I went the hard way and implemented all the methods again in each module using an interface.

However, now I experience that a method that only occures in one of the modules (but not in the interface) throws an exception:

Method or data member not found!

I am not entirely sure but I have the feeling that this is somehow related to the interface.

Therefore I'd like to know the following:

  • When implementing an interface in a module in VBA, is it still possible to write additional public subs for this module?
  • If it's not possible, what would be the correct pattern to append certain functionality to a module that implements an interface?
like image 833
speendo Avatar asked Jul 24 '26 00:07

speendo


1 Answers

If you declare a variable as the interface class, you can only call methods/properties of that interface, regardless of any other methods/properties exposed by the actual object type itself.

like image 197
Rory Avatar answered Jul 25 '26 20:07

Rory