top of page
  • John

Implement an Interface / Extract an Interface in VBA with VBE_Extras

VBE_Extras can automatically implement and extract Interfaces for you. Both of these functions are available in the Refactor sub-menu. This post isn't about WHY you would want to use Interfaces (though to read more about the Implements statement and about Interfaces in VBA, see the MS Docs), rather it is about HOW VBE_Extras can simplify the process of working with them.


The following is an example of extracting an Interface from one Class then implementing it in that same Class as well as in another Class.


So with an initial Class CCar:

And CPerson:

We decide we need a ToString() method (perhaps implemented in all Classes in the project) and so we first add it to CCar:

We then use VBE_Extras to extract an 'IToString' Interface:

The 'Extract Interface' dialog

Which does two things ... first it creates the IToString Interface as a new Class Module:

Second, it adds the 'Interface member' IToString_ToString() method to CCar and, due to the option we selected in the 'Extract Interface' dialog, that new 'Interface member' calls the existing ToString() member.

Now, having extracted the Interface from CCar, we want to implement it in CPerson so we again use VBE_Extras to help with that:

The 'Implement Interface' dialog

Which adds two methods to CPerson, the Private 'Interface member' IToString_ToString() and the (in this case 'default' ... due to the option selected in the 'Implement Interface' dialog) Object member ToString() which is accessible to client code.

Some code to test all of the above:


There you go ... Interface extracted and then implemented with a few clicks instead of loads of (error-prone) typing, using VBE_Extras!

1 comment

Recent Posts

See All
bottom of page