Using "Application.Run" to call parts of a class

DHS100

Board Regular
Joined
May 21, 2006
Messages
149
Hi,

I have a class module with various functions in it which are all quite similar. I have another function in this class which I want to act as the publicly exposed caller to these other function. It has two arguments, NameOfSub and NumberOfCalls. The idea is that the name of the sub-functions are passed in the argument to the caller function (along with the number of times to call it) and "application.run NameOfSub, NumberOfCalls" is used to call them. This seems to be failing and I think it might be because it's not a normal module? I get the error "1004 - Cannot run the macro XYZ. The macro may not be available in this workbook or all macros may be disabled". It's definitely not a trust issue or any security settings.

Is there a trick someone knows for doing this with classes?

Many thanks
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I'd suggest you use CallByName instead of Run.
 
Upvote 0
Re-reading your question, will the other routines be public or private? If they are private, CallByName won't work.
 
Upvote 0
If there's not too many of them, I'd be tempted to use a Select Case statement to run them. Failing that, if they're all very similar, could you combine them into a single Sub which uses parameters to change its behaviour?

WBD
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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