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

前端 未结 5 871
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-04 18:25

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

\'\'#inside class module
\'\'#classModule nam         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 19:20

    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
    

提交回复
热议问题