I do not understand why the members of an inherited interface are not available to VBA. They do not appear in the VBA Object Browser and a run-time error occurs if an attempt is made to use them.
Here is a full code sample which demonstrates the problem:
First I have a base class with a defined interface:
Expand|Select|Wrap|Line Numbers
- Public Interface IClassBase
- Property id As String
- Property Name As String
- End Interface
- <ClassInterface(ClassInterfaceType.None)> _
- Public Class ClassBase
- Implements IClassBase
- Private mstr_id As String
- Private mstr_Name As String
- Public Property id As String Implements IClassBase.id
- Get
- id = mstr_id
- End Get
- Set(ByVal value As String)
- mstr_id = value
- End Set
- End Property
- Public Property Name As String Implements IClassBase.Name
- Get
- Name = mstr_Name
- End Get
- Set(ByVal value As String)
- mstr_Name = value
- End Set
- End Property
- End Class
Expand|Select|Wrap|Line Numbers
- Public Interface IClassDerived
- Inherits IClassBase
- Property extra As String
- End Interface
- <ClassInterface(ClassInterfaceType.None)> _
- Public Class ClassDerived
- Inherits ClassBase
- Implements IClassDerived
- Private mstr_extra As String
- Public Property extra As String Implements IClassDerived.extra
- Get
- extra = mstr_extra
- End Get
- Set(ByVal value As String)
- mstr_extra = value
- End Set
- End Property
- End Class
The following code works around the problem. I make the members of the base class overridable:
Expand|Select|Wrap|Line Numbers
- Public Interface IVBAClassBase
- Property id As String
- Property Name As String
- End Interface
- <ClassInterface(ClassInterfaceType.None)> _
- Public Class VBAClassBase
- Implements IVBAClassBase
- Private mstr_id As String
- Private mstr_Name As String
- Public Overridable Property id As String Implements IVBAClassBase.id
- Get
- id = mstr_id
- End Get
- Set(ByVal value As String)
- mstr_id = value
- End Set
- End Property
- Public Overridable Property Name As String Implements IVBAClassBase.Name
- Get
- Name = mstr_Name
- End Get
- Set(ByVal value As String)
- mstr_Name = value
- End Set
- End Property
- End Class
Expand|Select|Wrap|Line Numbers
- Public Interface IVBAClassDerived
- Property id As String
- Property Name As String
- Property extra As String
- End Interface
- <ClassInterface(ClassInterfaceType.None)> _
- Public Class VBAClassDerived
- Inherits VBAClassBase
- Implements IVBAClassDerived
- Private mstr_extra As String
- Public Property extra As String Implements IVBAClassDerived.extra
- Get
- extra = mstr_extra
- End Get
- Set(ByVal value As String)
- mstr_extra = value
- End Set
- End Property
- Public Overrides Property id As String Implements IVBAClassDerived.id
- Get
- id = MyBase.id
- End Get
- Set(ByVal value As String)
- MyBase.id = value
- End Set
- End Property
- Public Overrides Property Name As String Implements IVBAClassDerived.Name
- Get
- Name = MyBase.Name
- End Get
- Set(ByVal value As String)
- MyBase.Name = id
- End Set
- End Property
- End Class
Am I missing something? Why does VBA not recurse into the inherited interfaces correctly? Is there a way of telling the type library exporter to expand the inherited interfaces?