Can't call VBA built in function with Application.Run

≯℡__Kan透↙ 提交于 2019-12-12 02:59:20

问题


In VBA a user defined subroutine or function can be called using the Application.Run method like so

Application.Run "macroName", arg1 ', ...

allowing for a crude simulation of delegates in VBA. However, built-in VBA functions cannot be called the same way

' Error 1004: Cannot run macro 'FileDateTime'. The macro may not be available ...
Debug.Print Application.Run("FileDateTime", "<some file path>") 

Given the string of a built-in functions name e.g. "FileDateTime", how can that function be called?

One work-around would be to create functions that merely return the result of the built-in function. But I am looking for a more direct solution.


回答1:


You do not need Application.run for this (and usage was incorrect as well):

Debug.Print FileDateTime("some file path")

EDIT: An alternative is to write your own macro:

function F_D_T(path as string)  
F_D_T = FileDateTime("somepath")  
end function

and call this macro using application.run



来源:https://stackoverflow.com/questions/25386827/cant-call-vba-built-in-function-with-application-run

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