Application.WorksheetFunction 与 WorksheetFunction

Application.WorksheetFunction vs. WorksheetFunction

这是一个相当简短的问题,可能很容易回答,但我自己现在没能回答:


示例数据:

A
B
C

示例代码:

With Sheet1
    Debug.Print Application.WorksheetFunction.Match("D", .Columns(1), 0)    'Option1
    Debug.Print Application.Match("D", .Columns(1), 0)                      'Option2
    Debug.Print WorksheetFunction.Match("D", .Columns(1), 0)                'Option3
End With

问题:

我知道选项 2 失去了智能感知并且不会进入调试模式,但是选项 1 和选项 3 的行为相同

虽然关于 WorksheetFunction 对象 says 的文档表明我们可以使用 Application 对象的 WorksheetFunction 属性,但它似乎工作得很好没有这样做。

那么,在这方面使用 Application 对象引用的附加值是什么?不使用它的缺点是什么?

我会说 Application 是全局上下文,当我们使用任何东西时,编译器无法在其当前上下文中找到它,它会在 Application 中查找,最终找到 Application.WorksheetFunction 在你的情况下。所以两者应该是等价的。 (这就是它在 JavaScript 中的工作方式)但我可能是错的。

更新

Documentation 指出,某些函数和属性可以在没有 Application. 的情况下调用,因此 Application.WorksheetFunction 等同于 WorksheetFunction 是正确的,但是错误的是,Application 充当全局上下文.

更新

According to this interesing articleApplication确实是默认对象:

The Application object is the Default Object, Excel assumes it even when it is not specified.