Doc Method

Returns an instance of the Document object by its index in the document collection of the application.

Applies to: Application object

Syntax

[[Set] documentRet =] object.Doc ( index )

The Doc method syntax has these parts:

Part Description
object Required. An expression that returns an instance of the Application object.
index Required. An expression that returns a Long value. Represents the index of the document in the document collection of the application.
documentRet Optional. A Document type variable.

Remarks

If index is less than 1 or greater than the number of open documents the Doc method returns Nothing. To find out the number of open documents, use the DocsNum method.

When creating a new document or opening an existing one the document is added to the end of the list of the open documents. That is, the index of the most recent open document is equal to the number of the oepn document.

Example

This example contains an application-level script. It demonstrates how to export all open documents to the PNG format. The example uses the Doc method to go through all open documents.

Dim curDoc As Document             ' Declare a document variable
For i=1 To thisApp.DocsNum()       ' Loop through all open documents
    Set curDoc = thisApp.Doc(i)    ' Get the i document
    If curDoc.Export( curDoc.Name & ".png", 0, False, False ) Then' Export document to png format
        TRACE curDoc.Name & ".png"     ' Display name of the file
    End If
Next i

 

See Also

CloseDoc method, CreateNewDoc method, DocByName method, DocsNum method, FirstDoc method, NextDoc method, OpenDoc method, Document object