简体   繁体   English

在VBA中实现接口的类模块中的其他方法

[英]Additional methods in a class module implementing an interface in VBA

I write a VBA macro for Microsoft Excel 2010. 我为Microsoft Excel 2010编写了一个VBA宏。

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? 在VBA中的模块中实现接口时,是否仍可以为此模块编写其他公共子接口?
  • If it's not possible, what would be the correct pattern to append certain functionality to a module that implements an interface? 如果不可能,那么将某些功能附加到实现接口的模块的正确模式是什么?

如果将变量声明为接口类,则只能调用该接口的方法/属性,而不管实际对象类型本身公开的任何其他方法/属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM