Documents collection

With the documents collection you can open and create documents and refer to particular documents by name or number.

For example:

Documents.Add("NORMAL")

The above line creates a new document based on the normal template and makes it the current document. This is exactly the same as selecting the New button on the toolbar.

Set mydoc = Documents.Add("NORMAL")

This has the same effect but also save a reference to the new document in a variable called mydoc. Mydoc is a Document object (see Document object for details) and you can use it, for example, to add text and print:

To open an existing document, use the Open method. As with the Add method, you can choose to save a reference to the document or not (which would depend on the other requirements of your macro):

Documents.Open("c:\my documents\myfile.aww")

or

Set mydoc = Documents.Open("c:\my documents\myfile.aww")

If you are opening several files in the same directory (or just want to change the current directory) you can use the following:

ChangeFileOpenDirectory("c:\my special folder")

The documents collection contains useful information about open documents as the following macro demonstrates:

MsgBox "There are " & Documents.Count & " documents, names to follow."

For each doc in Documents

MsgBox doc.GetTitle 

Next

Individual documents can be referred to by name or number. Suppose you had opened two documents, Write1.aww and Write2.aww, in that order then:

Documents(0).Activate

Documents("Write1.aww").Activate

are equivalent, as are:

Documents(1).Print

Documents("Write2.aww").Print