excel vba: Special Types - Functions as Arguments of Functions

后端 未结 3 1149
梦谈多话
梦谈多话 2020-12-07 23:03

There is no special type for functions in VBA. It is hard for me to see how to add functions as arguments to functions in Excel VBA.

What I am trying to accomplish i

3条回答
  •  隐瞒了意图╮
    2020-12-08 00:01

    Since VBA has it's roots in an interactive language, it has always had the ability to execute text:

    function f(g as string, x as string) as string
            f = application.run(g,x)
    end function
    
    MyStringA = f("functionA",string1)
    MyStringB = f("functionB",string1)
    

    Edit to Add: I think that in current versions of Excel, the application (Excel) can 'run' only things you can show in a spreadsheet cell. So that means functions, not subroutines. To execute a subroutine, wrap it up in a function wrapper:

    function functionA(x as string)
        Call MySubA(x)
    end function
    

提交回复
热议问题