Calling Procedure From A Module

  • Thread starter Thread starter Tony C
  • Start date Start date
T

Tony C

Hello Newsgroup

Is it possible to call a procedure from another module,
using variable(s) to specify the module and procedure
names? I need to use variables for specifying procedure
names due changes in data that are outside of my control.

Many Thanks


Tony C
 
I'm not aware of any way to do this with procedures in standard modules. It
can, however, be done with methods of a class. For example, given a class
Class1 with methods Method1 and Method2 we can do the following ...

Public Sub CallByVariable(MethodName As String)

Dim x As Class1

Set x = New Class1
CallByName x, MethodName, VbMethod


End Sub

The CallByName function takes an optional fourth argument, an array of
variants, that can be used to pass any required arguments to the method
being called.

I suppose you could write a class with a bunch of methods that are just
wrappers around your existing procedues.

I'm not sure why changes to data should necessitate something like this. If
we knew a little more about the background to the problem, it's possible
someone might be able to suggest a better solution.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Back
Top