tags:

views:

281

answers:

1

It is easy to call a function inside a classModule using CallByName How about functions inside standard module?

''#inside class module
''#classModule name: clsExample
  Function classFunc1()
     MsgBox "I'm class module 1"
  End Function
''# 
''#inside standard module
''#Module name: module1
  Function Func1()
     MsgBox "I'm standard module 1"
  End Function
''#
''# The main sub
Sub Main()
''# to call function inside class module
dim clsObj as New clsExample
Call CallByName(clsObj,"ClassFunc1")

''# here's the question... how to call a function inside a standard module
''# how to declare the object "stdObj" in reference to module1?
Call CallByName(stdObj,"Func1") ''# is this correct?

End Sub
A: 

CallByName works only with class objects.

If your subroutine is in a standard module, you can do this:

Sub Main()
    Module1.Func1
End Sub

If it's a function, then you'll probably want to capture the return value; something like this:

Sub Main()
    Dim var
    var = Module1.Func1
End Sub
Adam Bernier