[VBA] Allow any object that implements a specific interface as a parameter

trentt

New Member
Joined
Jun 28, 2018
Messages
7
I have a subroutine:

Sub ConvertExtractToXLSX(eExtract As Extract)

Where Extract is the interface I've implemented into another class:

ConveyExtract

I plan to make several more classes that implement Extract. I would like to be able to make ConvertExtractToXLSX accept any class I create that implements the Extract interface.

Is it possible to do this with VBA? Or would I be forced to use Optional parameters and add code to throw an error at runtime when no parameter is passed? Sure I could probably come up with a generic solution that fails at runtime if the incorrect object is used but it would be really nice to implement a solution that will error at compile time if it the wrong object is used.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top