Calling a Sub or Function contained in a module using "CallByName" in VB/VBA

Posted by Kratz on Stack Overflow See other posts from Stack Overflow or by Kratz
Published on 2010-04-22T23:21:16Z Indexed on 2010/04/22 23:23 UTC
Read the original article Hit count: 170

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about vb

Related posts about vba