Application.WorksheetFunction与WorksheetFunction [英] Application.WorksheetFunction vs. WorksheetFunction

查看:93
本文介绍了Application.WorksheetFunction与WorksheetFunction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This one is a rather short question and probably easy to answer, however I fail to do so myself at this point:

示例数据:

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


问题:

我知道option2失去了智能感知能力,不会进入调试模式,但是option1和option3的行为相同

I know that option2 lost intellisense and will not go into debug mode, however option1 and option3 behave the same

  • 智能感知原理
  • 引发错误,代码进入调试模式

WorksheetFunction 对象上的文档

Whereas documentation on the WorksheetFunction object says that we can use the WorksheetFunction property of the Application object, it seems to work just fine without doing so.

那么,在这方面使用 Application 对象引用的附加值是什么?将其省略的缺点是什么?

So, what is the added value to use Application object reference in this regard and what is the disadvantage of leaving it out?

推荐答案

我会说 Application 是全局上下文,当我们使用任何内容时,编译器都无法在其当前上下文中找到它,它会在 Application 中查找它,最终在您的情况下找到 Application.WorksheetFunction .因此,两者应相等.(这就是它在JavaScript中的工作方式)但是我可能错了.

I'd say that Application is global context and when we use anything, that compiler can't find in its current context, it looks it in Application, eventually finding Application.WorksheetFunction in your case. So both should be equivalent. (this is how it works in JavaScript) BUT I might be wrong.

更新

文档指出,其中一些函数和属性可以在没有Application.的情况下调用.因此,Application.WorksheetFunction等同于WorksheetFunction是正确的,但是,将Application用作全局上下文是错误的.

Documentation states, that some functions and properties can be called without Application., so it is true that Application.WorksheetFunction is equivalent to WorksheetFunction, but it is false, that Application serves as global context.

更新

According to this interesing article, Application is default object indeed:

Application对象是默认对象,即使未指定,Excel也会假定它.

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

这篇关于Application.WorksheetFunction与WorksheetFunction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆