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 is something like this:
function f(g as function, x as string) as string
f = g(x)
end function
Currently, I have a group of little functions all repeating themselves but with one call to a specific function.
From your code, function g takes a string parameter and returns a string. I suggest you create a class module called IStringFunction to act as the definition of an interface that all functions will support, thus:
Class Module: IStringFunction
Then, create a couple of example functions implementing this interface:
Class Module: HelloStringFunction
Class Module: GoodbyeStringFunction
…and finally, some test code to exercise the functions:
(Standard) Module: Test
Note that the class implementing the interface must have methods named
<Interface>_<Method>as in the example above, not just<Method>as you’d expect.Download the simple demo or intermediate demo here