<< Click to Display Table of Contents >> Document (object) |
Access paths:
▪Application à Documents à Item
▪Application à ActiveDocument
▪Application à Windows à Item à Document
▪Application à ActiveWindow à Document
1 Description
A Document object represents one individual document opened in TextMaker.
An individual Document object exists for each document. If you open or close documents, the respective Document objects will be created or deleted dynamically.
2 Access to the object
The individual Document objects can be accessed in the following ways:
▪All open documents are managed in the Application.Documents collection (type: Documents):
' Show the names of all open documents
For i = 1 To tm.Application.Documents.Count
MsgBox tm.Application.Documents.Item(i).Name
Next i
▪The active document can be accessed through the Application.ActiveDocument object:
' Show the name of the current document
MsgBox tm.Application.ActiveDocument.Name
▪Document is the Parent object for different objects which are linked with it, for example, BuiltInDocumentProperties or Selection:
' Show the name of the current document in an indirect way
MsgBox tm.Application.ActiveDocument.BuiltInDocumentProperties.Parent.Name
▪The objects Window and Selection include the object pointer to the document which belongs to them:
' Access the active document through the active document window
MsgBox tm.Application.ActiveWindow.Document.Name
3 Properties, objects, collections and methods
Properties:
▪Name R/O
▪FullName R/O
▪Path R/O
▪PageCount R/O
▪Saved
▪ReadOnly
▪EnableCaretMovement
▪MergeFileName
▪MergeFileFormat
▪MergeFileHeader
▪MergeRecord
Objects:
▪PageSetup → PageSetup
▪Selection → Selection
▪ActiveWindow → Window
▪Application → Application
▪Parent → Documents
Collections:
▪BuiltInDocumentProperties → DocumentProperties
▪Paragraphs → Paragraphs
▪Tables → Tables
▪FormFields → FormFields
Methods:
▪Activate
▪Close
▪Save
▪SaveAs
▪Select
▪MailMerge
▪PrintOut
▪MergePrintOut
Name (property, R/O)
Data type: String
Returns the name of the document (e.g. "Smith.tmdx").
FullName (property, R/O)
Data type: String
Returns the path and name of the document (e.g. "c:\Letters\Smith.tmdx").
Path (property, R/O)
Data type: String
Returns the path of the document (e.g. "c:\Letters").
PageCount (property, R/O)
Data type: Long
Returns the number of pages in the document.
Saved (property)
Data type: Boolean
Gets or sets the Saved property of the document. It indicates whether a document was changed since it was last saved:
▪If Saved is set to True, the document was not changed since it was last saved.
▪If Saved is set to False, the document was changed since it was last saved. When closing the document, the user will be asked if it should be saved.
Note: As soon as the user changes something in a document, its Saved property will be set to False automatically.
ReadOnly (property)
Data type: Boolean
Gets or sets the ReadOnly property of the document.
If the property is True, the document is protected against user changes. Users will not be able to edit, delete or add content.
If you set this property to True, the EnableCaretMovement property (see there) will be automatically set to False. Therefore, the text cursor cannot be moved inside the document anymore. However, you can always set the EnableCaretMovement property to True if you want to make cursor movement possible.
EnableCaretMovement (property)
Data type: Boolean
Gets or sets the EnableCaretMovement property of the document. This property is sensible only in combination with the ReadOnly property (see there).
If EnableCaretMovement is True, the text cursor can be moved freely inside a write-protected document. If it is set to False, cursor movement is not possible.
MergeFileName (property)
Data type: String
Gets or sets the name of the merge database to which the document is assigned.
MergeFileFormat (property)
Data type: Long (TmMergeType)
Gets or sets the file format of the merge database to which the document is assigned. The possible values are:
tmMergeCSVAnsi = 3
tmMergeDBaseAnsi = 5
tmMergeCSVDos = 64
tmMergeDBaseDos = 66
tmMergeDBaseUnicode = 69
MergeFileHeader (property)
Data type: Boolean
Gets or sets the option Use 1st record for field names. (In TextMaker, you will find this option in the dialog box of the ribbon command Mailings | Recipients group | Select database | Use existing database.)
This property is applicable only for the CSV files (tmMergeCSVAnsi, tmMergeCSVDos).
MergeRecord (property)
Data type: Long
Gets or sets the record number of the record shown in a merge document. Corresponds to the setting Show merge record on the View tab in the dialog box of the ribbon command File | Properties.
PageSetup (pointer to object)
Data type: Object
Returns the PageSetup object that you can use to access the page formatting of the document (paper format, margins, etc.).
Selection (pointer to object)
Data type: Object
Returns the Selection object that lets you access the currently selected text of the document. If nothing is selected, the object returns the current text cursor.
ActiveWindow (pointer to object)
Data type: Object
Returns the Window object that contains settings related to the document window of a document (for example, its height and width on the screen).
Application (pointer to object)
Data type: Object
Returns the Application object.
Parent (pointer to object)
Data type: Object
Returns the parent object, i.e. Documents.
BuiltInDocumentProperties (pointer to collection)
Data type: Object
Returns the DocumentProperties collection that you can use to access the document infos (title, subject, author, etc.).
Paragraphs (pointer to collection)
Data type: Object
Returns the Paragraphs collection, a collection of all paragraphs in the document.
Tables (pointer to collection)
Data type: Object
Returns the Tables collection, a collection of all tables in the document.
FormFields (pointer to collection)
Data type: Object
Returns the FormFields collection, a collection of all form objects in the document.
Activate (method)
Brings the document window to the front (if Visible is True for the document) and sets the focus to the document window.
Syntax:
Activate
Parameters:
none |
Return type:
none |
Example:
' Bring the first document of the Documents collection to the front
tm.Documents(1).Activate
Close (method)
Closes the document.
Syntax:
Close [SaveChanges]
Parameters:
SaveChanges (optional; type: Long or SmoSaveOptions) indicates whether the document should be saved or not. If you omit this parameter, the user will be asked – but only if the document was changed since it was last saved. The possible values for SaveChanges are: |
smoDoNotSaveChanges = 0 ' Don't ask, don't save
smoPromptToSaveChanges = 1 ' Ask the user
smoSaveChanges = 2 ' Save without asking
Return type:
none |
Example:
' Close the active document without saving
tm.ActiveDocument.Close smoDoNotSaveChanges
Save (method)
Saves the document.
Syntax:
Save
Parameters:
none |
Return type:
none |
Example:
' Save the active document
tm.ActiveDocument.Save
SaveAs (method)
Saves the document under a different name and/or path.
Syntax:
SaveAs FileName, [FileFormat]
Parameters:
FileName (type: String): Path and file name under which the document should be saved. |
FileFormat (optional; type: Long or TmSaveFormat) determines the file format. This parameter can take the following values (left: the symbolic constants, right: the corresponding numeric 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. |
Return type:
none |
Example:
' Save the current document under the given name in RTF format
tm.ActiveDocument.SaveAs "c:\docs\test.rtf", tmFormatRTF
Select (method)
Selects the entire document.
Syntax:
Select
Parameters:
none |
Return type:
none |
Example:
' Select the current document
tm.ActiveDocument.Select
You can then use the Selection object to change, for example, the text formatting or to copy the selected text to the clipboard.
PrintOut (method)
Prints the document on the currently selected printer.
Syntax:
PrintOut [From], [To]
Parameters:
From (optional; type: Long) indicates from which page to start. If omitted, printing starts from the first page. |
To (optional; type: Long) indicates at which page to stop. If omitted, printing stops at the last page. |
Return type:
Boolean (True if printing was successful) |
Example:
' Print out the pages 2-5 from the current document
tm.ActiveDocument.PrintOut 2, 5
MailMerge (method)
Transfers database fields from the assigned database into the document, using the record number specified in the dialog box of the ribbon command File | Properties.
Syntax:
MailMerge Options, [ReplaceFields]
Parameters:
Options (type: Long or TmMergeOption) indicates what kind of data will be merged. The possible values are: |
tmSingleFax = 1
tmSingleAddress = 2
tmMultipleFax = 3
tmMultipleAddress = 4
ReplaceFields (optional; type: Boolean) determines whether the database fields in the document should be physically replaced by the corresponding field contents. The default value is False. |
Return type:
none |
Example:
' Insert record #5 from the assigned database into the document
tm.ActiveDocument.MergeRecord = 5
tm.ActiveDocument.MailMerge tmSingleAddress, True
MergePrintOut (method)
Prints the document on the currently chosen printer as a merge document.
Syntax:
MergePrintOut [From], [To]
Parameters:
From (optional; type: Long) indicates the number of the first record to be printed. If omitted, printing starts with the first record. |
To (optional; type: Long) indicates the number of the last record to be printed. If omitted, printing stops at the last record. |
Return type:
Boolean (True if printing was successful) |
Example:
' Print the current merge document, records 99 through 105
tm.ActiveDocument.MergePrintOut 99, 105