The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ThisDocument object

ThisDocument object

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

See also Properties Methods Events

ThisDocumentMultiple Objects

The Microsoft Visual Basic for Applications (VBA) project of every Microsoft Visio document has a class module called ThisDocument. When referenced from code in the project, the ThisDocument object returns a reference to the project's Document object.

Version added



You can display the name of the VBA project's document in a message box with this statement, for example:

MsgBox ThisDocument.Name

You can get the first page of the VBA project's document by using this code, for example:

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

If you want to manipulate the document associated with your VBA project, use the ThisDocument object. 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.

The ActiveDocument property often, but not necessarily, returns a reference to the same document as the ThisDocument object. 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. Whether your code uses the ActiveDocument or ThisDocument object depends on the purpose of your program.

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. The new methods and properties are exposed just like the built-in methods and properties implemented by Visio. The new methods and properties aren't available when you reference other Document objects.

Note The ThisDocument object is not available to code that isn't part of the VBA project of a Visio document.