SetDocumentProperty

Syntax

SetDocumentProperty Name$, Type, Value[$], CustomOrBuiltIn

Remarks

Defines a document property for the active document. If Name$ is a built-in property that doesn't match the type specified by Type, or if it is a read-only property, an error occurs. Use the DocumentPropertyExists() function to determine whether a property called Name$ already exists.

For a list of the built-in properties available in Word, see DocumentPropertyName$(). In Word version 6.0, SetDocumentProperty is unavailable and generates an error.

Argument

Explanation

Name$

The name of the property. Name$ can be a built-in property or a custom property.

Type

The type of the property to be defined:

0 (zero) String

1 Number

2 Date

3 Yes or No

If Name$ is a built-in property and doesn't match the type specified by Type, an error occurs.

Value[$]

The property value. Value[$] must match the type specified by Type.

If Value[$] doesn't match the type specified by Type, an error occurs.

CustomOrBuiltIn

Specifies whether Name$ is a custom property or a built-in property:

0 (zero) or omitted Name$ is a custom property unless it appears in the list of built-in properties. If Name$ is a built-in property, SetDocumentProperty will update its value.

1 Name$ is a built-in property. If it is not one of the built-in properties, an error occurs.

2 Name$ is a custom property, regardless of whether a built-in property with the same name already exists.


Example

This example asks the user to insert the name of a customer and then assigns the name to the variable customerName$. The SetDocumentProperty instruction defines the custom property "Customer" with the value of customerName$. Note that this is done only if the custom property "Customer" is not already defined.


customerName$ = InputBox$("Please type the name of the customer", "Customer Name")
If DocumentPropertyExists("Customer") = 0 Then
    SetDocumentProperty("Customer", 0, customerName$, 2)
End If

See Also

DocumentPropertyExists(), GetDocumentProperty(), IsCustomDocumentProperty(), IsDocumentPropertyReadOnly(), SetDocumentPropertyLink