Documents Collection

The Documents collection contains all open documents. The Documents collection provides the means to access plot and worksheet documents. Use the Add method to create new plot or worksheet documents. Surfer allows creating plot documents, worksheets and grid files and provides the predefined values in srfDocTypes enumeration, for specifying the type of document to create:

Set srf = CreateObject("Surfer.Application")

srf.Documents.Add srfDocPlot ' Create a new, blank plot document

srf.Documents.Add srfDocWks ' Create a new, blank worksheet document

The Add method returns a reference to the Document object that was created. New grid documents are not created with the Documents collection Add method. You can create grid files by calling the Application object’s grid-related objects.

Use the Open method to open existing plot, worksheet, and grid files. The Open method returns a reference to the opened document.

Use the Item method to retrieve a reference to an open plot or worksheet document object. When iterating through a collection of documents, the document Type and Index properties can be used to determine the type and position of the document within the collection.

The following table provides the properties of the Documents collection:

Property

Description

Application

Returns the application object. It is a read-only property.

Count

Returns the number of documents in the collection. It is a read-only property.

Parent

Returns the parent object. It is a read-only property.

 

The following table provides the methods of the Documents collection:

Method

Description

Add

Adds a new document to the collection.

CloseAll

Closes all documents in the collection.

Item*

Returns an individual document.

Open

Opens an existing document.

Open2

Opens an existing document. This method is used instead of 'Open' when the worksheet being loaded is an Excel file.

SaveAll

Saves all documents in the collection.

*default method

Example 1

This script displays all the methods and properties in the Documents collection.

Example 2

The following script demonstrates how the Documents collection is used in reference to the Application object.

Sub Main

 

'Declares SurferApp as an object

Dim SurferApp As Object

 

'Creates an instance of the Surfer Application object and assigns

'it to the variable named "SurferApp"

Set SurferApp = CreateObject("Surfer.Application")

 

'Makes Surfer visible

SurferApp.Visible = True

 

'Declares Docs as an object

Dim Docs As Object

 

'Assigns the Documents collection to the variable named "Docs"

Set Docs = SurferApp.Documents

 

End Sub