[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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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