Documents (collection)

<< Click to Display Table of Contents >>

Documents (collection)

Access path: Application à Documents

 1  Description

The Documents collection contains all open documents. The individual elements of this collection are of the type Document.

 2  Access to the collection

There is exactly one instance of the Documents collection during the whole runtime of TextMaker. It is accessed through Application.Documents:

' Show the number of open documents

MsgBox tm.Application.Documents.Count

 

' Show the name of the first open document

MsgBox tm.Application.Documents(1).Name

 3  Properties, objects, collections and methods

Properties:

Count R/O

 

Objects:

Item Document (default object)

Application Application

Parent Application

 

Methods:

Add

Open

Close

Count (property, R/O)

Data type: Long

Returns the number of Document objects in the collection, i.e. the number of the currently open documents.

Item (pointer to object)

Data type: Object

Returns an individual Document object, i.e. an individual open document.

Which Document object you get depends on the value that you pass to Item. You can specify either the numeric index or the name of the desired document. Examples:

' Show the name of the first document

MsgBox tm.Application.Documents.Item(1).FullName

 

' Show the name of the document "Test.tmdx" (if currently open)

MsgBox tm.Application.Documents.Item("Test.tmdx").FullName

 

' You can also specify the full path

MsgBox tm.Application.Documents.Item("c:\Documents\Test.tmdx").FullName

Application (pointer to object)

Data type: Object

Returns the Application object.

Parent (pointer to object)

Data type: Object

Returns the parent object, i.e. Application.

Add (method)

Creates a new empty document, based either on the standard document template Normal.tmvx or any other document template you specify.

Syntax:

 Add [Template]

Parameters:

Template (optional; type: String): Path and file name of the document template on which your document should be based. If omitted, the standard template Normal.tmvx will be used.
If you omit the path or give only a relative path, TextMaker's default template path will be automatically prefixed. If you omit the file extension .tmvx, it will be automatically added.

Return type:

Object (a Document object which represents the new document)

Example:

Sub Example()

 Dim tm as Object

 Dim newDoc as Object

 

 Set tm = CreateObject("TextMaker.Application")

 tm.Visible = True

 Set newDoc = tm.Documents.Add

 MsgBox newDoc.Name

End Sub

You can use the Document object returned by the Add method like any other document. Alternatively, you can ignore the return value of the Add method and access the new document with the ActiveDocument method.

Open (method)

Opens an existing document.

Syntax:

 Open FileName, [ReadOnly], [Password], [WritePassword], [Format]

Parameters:

FileName (type: String): Path and file name of the document or document template to be opened.
ReadOnly (optional; type: Boolean): Indicates whether the document should be opened only for reading.
Password (optional; type: String): The read password for password-protected documents. If you omit this parameter for a password-protected document, the user will be asked to input the read password.
WritePassword (optional; type: String): The write password for password-protected documents. If you omit this parameter for a password-protected document, the user will be asked to input the write password.
Format (optional; Typ: Long bzw. TmSaveFormat): The file format of the document to be opened. Possible values:

 tmFormatDocument          =  0 ' TextMaker document

 tmFormatTemplate          =  1 ' TextMaker document template

 tmFormatWinWord97         =  2 ' Microsoft Word 97 and 2000

 tmFormatOpenDocument      =  3 ' OpenDocument, OpenOffice.org, StarOffice

 tmFormatRTF               =  4 ' Rich Text Format

 tmFormatPocketWordPPC     =  5 ' Pocket Word for Pocket PCs

 tmFormatPocketWordHPC     =  6 ' Pocket Word for Handheld PCs (Windows CE)

 tmFormatPlainTextAnsi     =  7 ' Text file with Windows character set

 tmFormatPlainTextDOS      =  8 ' Text file with DOS character set

 tmFormatPlainTextUnicode  =  9 ' Text file with Unicode character set

 tmFormatPlainTextUTF8     = 10 ' Text file with UTF8 character set

 tmFormatHTML              = 12 ' HTML document

 tmFormatWinWord6          = 13 ' Microsoft Word 6.0

 tmFormatPlainTextUnix     = 14 ' Text file for UNIX, Linux, FreeBSD

 tmFormatWinWordXP         = 15 ' Microsoft Word XP and 2003

 tmFormatTM2006            = 16 ' TextMaker 2006 document

 tmFormatOpenXML           = 17 ' Microsoft Word 2007 and later

 tmFormatTM2008            = 18 ' TextMaker 2008 document

 tmFormatOpenXMLTemplate   = 22 ' Microsoft Word document template 2007 and later

 tmFormatWinWordXPTemplate = 23 ' Microsoft Word document template XP and 2003

 tmFormatTM2012            = 27 ' TextMaker 2012 document

 tmFormatTM2016            = 28 ' TextMaker 2016 document

 tmFormatTM2016Template    = 29 ' TextMaker 2016 document template

If you omit this parameter, the value tmFormatDocument will be assumed.
Tip: Independent of the value for the FileFormat parameter, TextMaker always tries to determine the file format by itself and ignores evidently false inputs.

Return type:

Object (a Document object which represents the opened document)

Examples:

' Open a document

tm.Documents.Open "c:\docs\test.tmdx"

 

' Open a document only for reading

tm.Documents.Open "c:\docs\Test.tmdx", True

Close (method)

Closes all currently open documents.

Syntax:

 Close [SaveChanges]

Parameters:

SaveChanges (optional; type: Long or SmoSaveOptions) indicates whether the documents which were changed since they were last saved should be saved or not. If you omit this parameter, the user will be asked to indicate it (if necessary). The possible values are:

 smoDoNotSaveChanges = 0      ' Don't ask, don't save

 smoPromptToSaveChanges = 1   ' Ask the user

 smoSaveChanges = 2           ' Save without asking

Return type:

none

Example:

' Close all open documents without saving them

tm.Documents.Close smoDoNotSaveChanges