Home » excel » excel – Additional methods in a class module implementing an interface in VBA

excel – Additional methods in a class module implementing an interface in VBA

Posted by: admin April 23, 2020 Leave a comment

Questions:

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?
How to&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.