DocumentProperty (object)

<< Click to Display Table of Contents >>

DocumentProperty (object)

Access paths:

Application à Documents à Item à BuiltInDocumentProperties à Item

Application à ActiveDocument à BuiltInDocumentProperties à Item

 1  Description

A DocumentProperty object represents one individual document property of a document, for example, the title, the author, or the number of words in a document.

 2  Access to the object

The individual DocumentProperty objects can be accessed solely through enumerating the elements of the collection DocumentProperties.

For each opened document, there is exactly one instance of the DocumentProperties collection, namely BuiltInDocumentProperties in the Document object:

' Set the title of the active document to "My Story"

tm.ActiveDocument.BuiltInDocumentProperties.Item(smoPropertyTitle) = "My story"

 3  Properties, objects, collections and methods

Properties:

Name R/O

Value (default property)

Valid

Type

 

Objects:

Application Application

Parent BuiltInDocumentProperties

Name (property, R/O)

Data type: String

Returns the name of the document property. Examples:

' Show the name of the document property smoPropertyTitle, i.e. "Title"

MsgBox tm.ActiveDocument.BuiltInDocumentProperties.Item(smoPropertyTitle).Name

 

' Show the name of the document property "Author", i.e. "Author"

MsgBox tm.ActiveDocument.BuiltInDocumentProperties.Item("Author").Name

Value (property)

Data type: String

Gets or sets the content of a document property.

The following example assigns a value to the document property "Title" defined by the numeric constant smoPropertyTitle and then reads its value again using the string constant "Title":

Sub Example()

 Dim tm as Object

 

 Set tm = CreateObject("TextMaker.Application")

 tm.Documents.Add ' Add a new empty document

 

 ' Set the new title (using the numeric constant smoPropertyTitle)

 tm.ActiveDocument.BuiltInDocumentProperties.Item(smoPropertyTitle).Value =

 "New title"

 

 ' Get the exact same property again (using the string this time)

 MsgBox tm.ActiveDocument.BuiltInDocumentProperties.Item("Title").Value

 

End Sub

Since Item is the default object of the DocumentProperties and Value is the default property of DocumentProperty, the example can be written clearer in the following way:

Sub Example()

 Dim tm as Object

 

 Set tm = CreateObject("TextMaker.Application")

 tm.Documents.Add ' Add a new empty document

 

 ' Set the new title (using the numeric constant smoPropertyTitle)

 tm.ActiveDocument.BuiltInDocumentProperties(smoPropertyTitle) = "New title"

 

 ' Get the exact same property again (using the string this time)

 MsgBox tm.ActiveDocument.BuiltInDocumentProperties("Title")

 

End Sub

Valid (property, R/O)

Data type: Boolean

Returns True if the document property is available in TextMaker.

Background: The list of document properties also contains items that are available only in PlanMaker (for example, smoPropertySheets, "Number of sheets"). When working with TextMaker, you can retrieve only those document properties that are known to this program – otherwise an empty value will be returned (VT_EMPTY).

The Valid property allows you to test whether the respective document property is available in TextMaker before using it. Example:

Sub Main()

 Dim tm as Object

 Dim i as Integer

 

 Set tm = CreateObject("TextMaker.Application")

 

 tm.Visible = True

 tm.Documents.Add ' Add an empty document

 

 With tm.ActiveDocument

         For i = 1 to .BuiltInDocumentProperties.Count

                 If .BuiltInDocumentProperties(i).Valid then

                         Print i, .BuiltInDocumentProperties(i).Name, "=", _

                                 .BuiltInDocumentProperties(i).Value

                 Else

                         Print i, "Not available in TextMaker"

                 End If

         Next i

 End With

 

End Sub

Type (property, R/O)

Data type: Long (SmoDocProperties)

Returns the data type of the document property. In order to evaluate a document property correctly, you must know its type. For example, Title (smoPropertyTitle) is a string value, whereas Creation Date (smoPropertyTimeCreated) is a date. The possible values are:

smoPropertyTypeBoolean   = 0 ' Boolean

smoPropertyTypeDate      = 1 ' Date

smoPropertyTypeFloat     = 2 ' Floating-point number

smoPropertyTypeNumber    = 3 ' Integer number

smoPropertyTypeString    = 4 ' String

Application (pointer to object)

Data type: Object

Returns the Application object.

Parent (pointer to object)

Data type: Object

Returns the parent object, i.e. BuiltInDocumentProperties.