Search notes:

Excel Object Model: Application.Run

Application.run can be used to dynamically run a sub or function by a name stored in a variable.
The optional parameters of run() are passed to the sub/function being called.
In case of a function, the return value of the function is returned also from run()
option explicit

sub main()

    application.run "runSub", "subTwo"

    debug.print application.run("funcOne",     19 ,     23 )
    debug.print application.run("funcTwo", "Hello", "World")

end sub

sub runSub(subName as string)
    debug.print "runSub tries to run " & subName
    application.run subName
end sub

sub subOne()
    debug.print "subOne was called"
end sub

sub subTwo()
    debug.print "subTwo was called"
end sub

function funcOne(a as long, b as long) as long
    funcOne = a + b
end function

function funcTwo(a as string, b as string) as string
    funcTwo = a & " " & b
end function

Running a sub in another workbook

It's possible to run a macro in another (possibly unopened) workbook:
application.run "'C:\users\rene\test.xlsm'!testSub"
If the other workbook is currently closed, it will be opened by this call.

See also

The Visual Basic for Application function callByName and application.onTime.
The run() method of the range object.
This example demonstrates how it is possible to create a dynamic VBA module, place a sub into it and then call it using application.run.
Excel's application object.
The comparable application.run() of Access.

Index