无法调用带有Application.Run的内置函数的VBA [英] Can't call VBA built in function with Application.Run
问题描述
在VBA中,可以像这样使用Application.Run
方法调用用户定义的子例程或函数
In VBA a user defined subroutine or function can be called using the Application.Run
method like so
Application.Run "macroName", arg1 ', ...
允许在VBA中对代理进行粗略的模拟. 但是,内置的VBA函数不能以相同的方式调用
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>")
给出内置函数名称例如"FileDateTime"的字符串,该函数如何调用?
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.
推荐答案
您不需要为此运行Application.run(并且用法也不正确):
You do not need Application.run for this (and usage was incorrect as well):
Debug.Print FileDateTime("some file path")
一种替代方法是编写您自己的宏:
An alternative is to write your own macro:
function F_D_T(path as string)
F_D_T = FileDateTime("somepath")
end function
并使用application.run调用此宏
and call this macro using application.run
这篇关于无法调用带有Application.Run的内置函数的VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!