Using named arguments with Application.Run (or equiv)

China☆狼群 提交于 2019-12-11 05:29:33

问题


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



来源:https://stackoverflow.com/questions/16399471/using-named-arguments-with-application-run-or-equiv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!