ActiveDocument property

Microsoft Visio Developer Reference

ActiveDocument property

        object;DAR_Objects_(A-M)_1015.htm">

Returns the active Document object, the document shown in the active window.

Version added

2.0

Syntax

objRet = object.ActiveDocument

objRet

A Document object that represents the active document.

object

Required. An expression that returns the Application object that owns the document.

Remarks

When no documents are open, there is no active document and the ActiveDocument property returns the value Nothing and does not raise an exception.

If your code is in the Microsoft Visual Basic for Applications (VBA) project of a Visio document, the ActiveDocument property often, but not necessarily, returns a reference to the ThisDocument object, a class module in the VBA project of every Visio document. If the ThisDocument object is shown in the active window, then the ActiveDocument object and the ThisDocument object refer to the same document. When the ThisDocument object is referenced from code in a project, it returns a reference to the project's Document object.

Whether you use the ActiveDocument object or the ThisDocument object depends on the purpose of your code.

You can compare the result returned by the ActiveDocument property with the value Nothing to determine if a document is active. If the value of the Application.Documents.Count property is greater than zero, then at least one document is open and active.