Excel 2010 VBA 编辑器中的自动完成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27528488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Autocompletion in Excel 2010 VBA Editor
提问by mrbela
I'm new in VBA. In the editor in Excel 2010 there is the opportunity of an autocompletion by pressing CTRL + Space.
我是 VBA 新手。在 Excel 2010 的编辑器中,可以通过按 CTRL + Space 来自动完成。
But sometimes, it doesn't work.. For example when I type in "ActiveSheet." I can't examine the possible methods and variables the object have..
但有时,它不起作用.. 例如,当我输入“ActiveSheet”时。我无法检查对象可能具有的方法和变量。
But when I type in:
但是当我输入时:
Set sheet = Workbooks.Open(file, True, True)
sheet.
and hit CTRL+Space I can see all possibilities..
并按 CTRL+Space 我可以看到所有可能性..
Thanks for your help!
谢谢你的帮助!
回答by Dick Kusleika
VBA only gives you the properties and methods when there is no ambiguity in the data type. The ActiveSheet can be a Worksheet object, Macrosheet, and probably a couple other things I don't remember.
VBA 仅在数据类型没有歧义时才为您提供属性和方法。ActiveSheet 可以是一个 Worksheet 对象、Macrosheet,可能还有一些我不记得的东西。
If you go to the Object Browser (F2) and look up either ActiveSheet or the Item property of the Sheets class, you'll see that they returns an Object data type. Object is a generic data type that can hold any object (kind of like Variant). Because VBA doesn't know what object is behind the Object, it can't give you a list of properties and methods.
如果您转到对象浏览器 (F2) 并查找 ActiveSheet 或 Sheets 类的 Item 属性,您将看到它们返回对象数据类型。Object 是一种通用数据类型,可以保存任何对象(有点像 Variant)。因为 VBA 不知道 Object 后面是什么对象,所以它不能给你一个属性和方法的列表。
You don't get that list by using Set sheet = ...
, you get it because previously in your code you declared sheet
as Worksheet (probably). While Sheet.Item (and Activesheet) returns an Object, there is no ambiguity when you declare something as Worksheet.
您不会通过使用获得该列表Set sheet = ...
,而是因为之前在您的代码中声明sheet
为 Worksheet (可能)而获得它。虽然 Sheet.Item(和 Activesheet)返回一个对象,但当您将某些内容声明为 Worksheet 时没有歧义。