ThisDocument 对象 (Visio)ThisDocument object (Visio)

每个 Visio 文档的 Visual Basic for Applications (VBA) 项目都有一个名为ThisDocument的类模块。The Visual Basic for Applications (VBA) project of every Visio document has a class module called ThisDocument. 从项目中的代码引用时, ThisDocument对象将返回对项目的**Document** 对象的引用。When referenced from code in the project, the ThisDocument object returns a reference to the project's Document object.

您可以使用以下语句在消息框中显示 VBA 项目的文档的名称。You can display the name of the VBA project's document in a message box by using the following statement.

MsgBox ThisDocument.Name

您可以使用以下代码获取 VBA 项目文档的第一页。You can get the first page of the VBA project's document by using the following code.

Dim vsoPage As Visio.Page 
Set vsoPage = ThisDocument.Pages.Item(1)

说明Remarks

如果要对与 VBA 项目关联的文档进行操作,请使用 ThisDocument 对象。If you want to manipulate the document associated with your VBA project, use the ThisDocument object.

如果要对不一定与 VBA 项目关联的文档进行操作,请从 Documents 集合中选取一个 Document 对象。If you want to manipulate a document, but not necessarily the document associated with your VBA project, get a Document object from the Documents collection.

ActiveDocument 属性经常(但不一定)返回与 ThisDocument 对象相同的文档的引用。The ActiveDocument property often, but not necessarily, returns a reference to the same document as the ThisDocument object. 如果在 Visio 活动窗口中显示的文档是包含 ThisDocument 对象项目的文档,则 ActiveDocumentThisDocument 对象是相同的。The ActiveDocument and ThisDocument objects are the same if the document shown in the Visio active window is the document containing the ThisDocument object's project. 您的代码使用的是 ActiveDocument 还是 ThisDocument 对象取决于程序的目的。Whether your code uses the ActiveDocument or ThisDocument object depends on the purpose of your program.

备注

您可以扩展项目的 Document 对象的属性和方法集,方法是将公共属性和方法添加到该项目的 ThisDocument 类模块中。You can extend the set of properties and methods of a project's Document object by adding public properties and methods to that project's ThisDocument class module. 公开这些新属性和方法的方式与由 Visio 实现的内置方法和属性一样。The new methods and properties are exposed just like the built-in methods and properties implemented by Visio.

当引用其他 Document 对象时,这些新的方法和属性不可用。The new methods and properties are not available when you reference other Document objects. 对于不属于 Visio 文档 VBA 项目的代码,ThisDocument 对象不可用。The ThisDocument object is not available to code that is not part of the VBA project of a Visio document.

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.