3

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?
5
  • 3
    If you declare a variable as the interface class, you can only call methods/properties of that interface. Commented Jul 4, 2016 at 14:08
  • you mean static binding, right? However, I declared the variable as the "real class" not the interface class... Should it work then? Commented Jul 4, 2016 at 14:14
  • 2
    Yes it should. Unless you post the code, we can't tell you why it doesn't. Commented Jul 4, 2016 at 14:15
  • of course. But I guess nobody would like to read the whole code. When you tell me it should work, I will try to make a minimal example. Commented Jul 4, 2016 at 14:20
  • @Rory thank you for your comment! Knowing that it should work I found the source of the problem myself (and you were right, it was a problem with the variable declaration). As your comment the question comprehensively, I would like to accept it. Would you like to formulate it into an answer? Commented Jul 5, 2016 at 7:09

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.