Using named arguments with Application.Run (or equ

2019-08-13 13:30发布

问题:

I'm attempting to pass arguments to a VBA function via a string (user input from form)

The following code is throwing Runtime Error 2517 (Access cannot find the procedure '.') after it finishes running function a

Public Function a(Optional al As Boolean, Optional bl As Boolean)
    Debug.Print al
End Function

Public Sub b()
    Application.Run a, "bl:=false, al:=false"
End Sub

The correct syntax for the function would be Application.Run "a", "false", "false" but this approach cannot handle named arguments (which is a must for me)

I tried using the eval() function but it cannot resolve the named arguments.

Any suggestions on runtime error or any way in which I can pass a string with named arguments (as above) to a VBA function?

回答1:

A is a function, functions return results try make it a procedure and just call it forget using application.run