0

In a variable I stored a function name, but when I try to call it from a sub() I've got some errors "Type mismatch", maybe I'm doing it wrong.

Public Sub test()

    Dim list As Collection
    Dim functionName As String
    
    functionName = "asBuiltComplete()"
    Set list = functionName
    For Each rs In list
        Debug.Print rs.getId & " " & rs.getActualDate & " " & rs.getBlDate
    Next

End Sub
1
  • You can try playing around with Eval(). Commented Sep 16, 2020 at 18:59

1 Answer 1

3

You can use Application.Run:

functionName = "asBuiltComplete"
Set list = Application.Run(functionName)

While you could use Eval, Application.Run is somewhat more limited in functionality so has less chance of weirdness.

However, this is bad code. You generally want to avoid dynamic function names whenever feasible, and just call the function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.