DocumentProperty (object)

<< Click to Display Table of Contents >>

DocumentProperty (object)

Access paths:

Application à Workbooks à Item à BuiltInDocumentProperties à Item

Application à ActiveWorkbook à 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 charts 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 open document there is exactly one instance of the DocumentProperties collection, namely BuiltInDocumentProperties in the Workbook object:

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

pm.ActiveWorkbook.BuiltInDocumentProperties.Item(smoPropertyTitle) = "My calculation"

 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 pm.ActiveWorkbook.BuiltInDocumentProperties.Item(smoPropertyTitle).Name

 

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

MsgBox pm.ActiveWorkbook.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 Main()

 Dim pm as Object

 

 Set pm = CreateObject("PlanMaker.Application")

 pm.Workbooks.Add ' Add a new empty document

 

 With pm.ActiveWorkbook

 

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

  .BuiltInDocumentProperties.Item(smoPropertyTitle).Value = "New title"

 

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

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

 

 End With

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 Main()

 Dim pm as Object

 

 Set pm = CreateObject("PlanMaker.Application")

 pm.Workbooks.Add ' Add a new empty document

 

 With pm.ActiveWorkbook

 

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

  .BuiltInDocumentProperties(smoPropertyTitle) = "New title"

 

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

   MsgBox .BuiltInDocumentProperties("Title")

 

 End With

End Sub

Valid (property, R/O)

Data type: Boolean

Returns True if the document property is available in PlanMaker.

Background: The list of document properties also contains items that are available only in TextMaker (for example, smoPropertyChapters, "Number of chapters"). When working with PlanMaker, you can retrieve only those document properties that are known by 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 PlanMaker before using it. Example:

Sub Main()

 Dim pm as Object

 Dim i as Integer

 

 Set pm = CreateObject("PlanMaker.Application")

 

 pm.Visible = True

 pm.Workbooks.Add ' add an empty document

 

 With pm.ActiveWorkbook

         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 PlanMaker"

                 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.