Document Object

Home Page (Objects)OverviewFAQReference

The Document object represents an open document.

The Document object has the following properties and methods:

Properties
Active Path
ActiveWindow ReadOnly
Application Saved
FullName Type
Name Windows
Parent

Methods
Close Redo
NewWindow Save
PrintOut Undo

Each open document in Developer Studio is represented by a Document object. This object has members (properties, methods, and events) that you can use to manipulate the document.

If a document is a text file, that document also has a TextDocument object. This object has all the members of a Document object and also has members that allow you to access text-specific attributes of the document.

Use a document's Type property to determine which members you can access. If the type is "Generic," the document is not a text document and you can access only Document members. If the type is "Text," the document is a text document, and you can access TextDocument members as well as Document members.

In VBScript macros, you access TextDocument members by automatically using late binding. In add-ins however, you can also access TextDocument members by using early binding. Early binding offers better performance than late binding by making calls into the interface faster at run time.

You can access the current document by using the ActiveDocument property of the Application object.

All open documents belong to the documents collection represented by the Documents object. You can find a particular document by iterating through this collection.

Using a Dual Interface to Access This Object

This section about dual interfaces is useful for writing add-ins or automating Developer Studio across processes. This section is not applicable to writing VBScript macros.

The Document object implements the IGenericDocument dual interface. Through this interface, add-ins can directly access the members (properties, methods, and events) of this object and can employ early binding to make calls into these members faster at run time.

Add-ins written in Visual C++ can access members of the Document object by using the header files in Vc98\Include\objmodel. However, if you use the Developer Studio Add-in Wizard to create an add-in, the wizard automatically includes these header files in your source code.

The following table shows the header files you need for the Document object:

Header file Description
appauto.h Declares the dual interfaces.
appguid.h Declares the GUIDs used to identify the interfaces.
appdefs.h Declares additional information needed to use the interfaces, such as error IDs and enumerated constants.

Add-ins written in Visual Basic can access members of the Document object by using the Visual Studio '97 Shared Objects type library, located in Msdev98\bin\devshl.dll.

Note   Visual Studio '97 Shared Objects is the name that appears in the Visual Basic References dialog box.