简体   繁体   English

VBA 对象模型参考文档

[英]VBA Object Model reference documentation

Is there a place where I can simply find the Object Model hierarchy and kind of API for VBA for Excel 2013?有没有一个地方可以简单地找到对象模型层次结构和 VBA for Excel 2013 的 API 种类?

I am looking at MSDN URL http://msdn.microsoft.com/en-us/library/office/ff841127(v=office.15).aspx我正在查看 MSDN URL http://msdn.microsoft.com/en-us/library/office/ff841127(v=office.15).aspx

But that seems confusing.但这似乎令人困惑。

Example:例子:

If I am writing如果我在写

Selection.Interior.ColorIndex = -4142

I would like to have an API (online or offline) to understand the Object Models starting with Selection and work (and explore) my way to ColorIndex.我想要一个 API(在线或离线)来了解从Selection开始的对象模型,并以我的方式工作(和探索)到 ColorIndex。 By reading the associated documentation as well.通过阅读相关的文档。

The only way I think that's possible is by having a structured document like Java Docs.我认为这是可能的唯一方法是拥有像 Java Docs 这样的结构化文档。

Any references/tips will help.任何参考/提示都会有所帮助。

System Info:
MS Excel 2013
VBA
Windows 8, 64 bit

UPDATE: While searching for answers, I got the below image from http://msdn.microsoft.com/en-us/library/aa141044.aspx更新:在寻找答案时,我从http://msdn.microsoft.com/en-us/library/aa141044.aspx得到了下面的图片

对象模型层次结构

Update: Based on entry by user Oliver below: My office help doesn't seem to be working.更新:根据以下用户 Oliver 的输入:我的办公室帮助似乎不起作用。CLView.EXE 问题

Generally, if a variable or other identifier can be resolved to a specific type, then Intellisense will show you the members of that type.通常,如果变量或其他标识符可以解析为特定类型,则 Intellisense 将向您显示该类型的成员。 For example:例如:

Application.

will bring up a list of members.将显示成员列表。

Selection is a special case because although the currently selected item is often a range of cells, it could be something else as well - part of a chart sheet for example. Selection是一种特殊情况,因为尽管当前选定的项目通常是一系列单元格,但它也可能是其他内容 - 例如图表工作表的一部分。


You can discover the underlying type of the object which Selection refers to, by adding a watch ( Debug -> Add Watch... ).您可以通过添加监视( Debug -> Add Watch... )来发现Selection所指对象的基础类型。 Type Selection in the Expression box, and set the context to (All Procedures) and (All Modules) if it's not set that way already.表达式框中键入Selection ,并将上下文设置为(所有过程)(所有模块)(如果尚未设置为这种方式)。

In the Watches window, you will see the actual type of the object referred to by Selection , and you can expand the + to see its properties.Watches窗口中,您将看到Selection引用的对象的实际类型,您可以展开+以查看其属性。 If the type says Object/Range , (meaning the type of the expression is Object and the type of the object referred to by the expression is Range ), one of the properties will be Interior .如果类型为Object/Range ,(意味着表达式的类型是Object并且表达式引用的对象的类型是Range ),则属性之一将是Interior If you look at the type column for Interior , you'll see Interior/Interior , because the type of the Interior property is indeed the Interior type.如果您查看Interior的类型列,您会看到Interior/Interior ,因为Interior属性的类型确实是Interior类型。

If you type the following in code:如果您在代码中键入以下内容:

ActiveCell.

Intellisense will show you a list of members, including the Interior property, because the type of the ActiveCell property is the Range type. Intellisense 将向您显示成员列表,包括Interior属性,因为ActiveCell属性的类型是Range类型。


Some other powerful tools for investigating the object model:其他一些用于研究对象模型的强大工具:

  • The Object Browser ( View -> Object Browser ) shows you a list of types available to your project, based on the libraries which the project references (can be viewed/changed at Tools -> References... ).对象浏览器View -> Object Browser )根据项目引用的库(可以在Tools -> References... 中查看/更改)显示您的项目可用的类型列表。 When a type is selected, you will see a list of members for that type.选择类型后,您将看到该类型的成员列表。 You can filter the types by library and/or by name.您可以按库和/或按名称过滤类型。 Members in the <globals> type can be used without any object references -- Interior needs some Range object to be used, but Selection can be used by itself. <globals>类型的成员可以在没有任何对象引用的情况下使用—— Interior需要使用一些Range对象,但Selection可以单独使用。
  • The Immediate window ( View -> Immediate window ) lets you evaluate expressions (preface with a ? -- eg ?ActiveWorkbook.Sheets.Count ) and run code in place (such as ActiveWorkbook.Save )立即窗口查看- >立即窗口),可以计算表达式(前言用? -如?ActiveWorkbook.Sheets.Count )和运行代码的地方(如ActiveWorkbook.Save

The Excel Developer reference is most probably right on your computer, it's just difficult to find: Excel Developer 参考很可能就在您的计算机上,只是很难找到:

Manual way:手动方式:

  1. Start Excel启动 Excel
  2. Hit Alt-F11 to enter VBA Editor按 Alt-F11 进入 VBA 编辑器
  3. On the Menu Bar, choose "?"->Microsoft Visual Basic Help在菜单栏上,选择“?”->Microsoft Visual Basic 帮助

Now you are looking at the Excel-VBA Help and you can even search it in the top left box for "Selection".现在您正在查看 Excel-VBA 帮助,您甚至可以在左上角的框中搜索“选择”。

Direct Link:直接链接:

"C:\Program Files (x86)\Microsoft Office\Office15\CLVIEW.EXE" "EXCEL.DEV" "Microsoft Office Excel"

(At least this worked for Office 2007, i assume it does for 2013 as well) (至少这适用于 Office 2007,我认为它也适用于 2013 年)

Do you mean, while coding you would like to see function/sub explanations like JavaDoc?您的意思是,在编码时您希望看到像 JavaDoc 这样的函数/子解释吗? Unfortunately this is not standard in VBA.不幸的是,这不是 VBA 的标准。

However you might want to take a look into this Is there a good VB6 documentation system similar to Javadoc?但是你可能想看看这个是否有一个类似于 Javadoc 的好的 VB6 文档系统?

Another way to "see" the underlying Object Model called by Excel is to use the macro recorder. “查看”Excel 调用的底层对象模型的另一种方法是使用宏记录器。

  1. Open the excel sheet and the VBA environment (ALT+F11) side by side.并排打开 Excel 工作表和 VBA 环境 (ALT+F11)。
  2. Goto Developer tab and click "Record Macro".转到“开发人员”选项卡,然后单击“录制宏”。
  3. From the VBE open the module1 from project explorer (this is where exlce writes macro by default).在 VBE 中,从项目资源管理器中打开 module1(这是 exlce 默认写入宏的地方)。
  4. Now make changes in your worksheet and see what code Excel is writing.现在在您的工作表中进行更改并查看 Excel 正在编写什么代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM