问题
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