Skip to main content

DocumentProperties.Add method

Creates a new custom document property. You can add a new document property only to the custom DocumentProperties collection.

Syntax

expression.Add (Name, LinkToContent, Type, Value, LinkSource)

expression Required. A variable that represents a DocumentProperties object. The custom DocumentProperties object.

Parameters

Name Required/Optional Data type Description
Name Required String The string of the Name of the property.
LinkToContent Required Boolean Specifies whether the LinkToContent property is linked to the contents of the container document. If this argument is True, the LinkSource argument is required; if it's False, the Value argument is required.
Type Optional Variant The data type of the Type property. Can be one of the following MsoDocProperties constants: msoPropertyTypeBoolean, msoPropertyTypeDate, msoPropertyTypeFloat, msoPropertyTypeNumber, or msoPropertyTypeString.
Value Optional Variant The data value of the Value property, if it's not linked to the contents of the container document. The value is converted to match the data type specified by the Type argument, and if it can't be converted, an error occurs. If LinkToContent is True, the argument is ignored, and the new document property is assigned a default value until the linked property values are updated by the container application (usually when the document is saved).
LinkSource Optional Variant Ignored if LinkToContent is False. The source of the LinkSource property. The container application determines what types of source linking you can use. For example, DDE links use the "Server|Document!Item" syntax.

Remarks

If you add a custom document property to the DocumentProperties collection that's linked to a given value in an Office document, you must save the document to see the change to the DocumentProperty object.

Example

This example, which is designed to run in Word, adds three custom document properties to the DocumentProperties collection.

With ActiveDocument.CustomDocumentProperties
    .Add Name:="LastModifiedBy", _
        LinkToContent:=True, _
        Type:=msoPropertyTypeString, _
        LinkSource:=Author
    .Add Name:="CustomNumber", _
        LinkToContent:=False, _
        Type:=msoPropertyTypeNumber, _
        Value:=1000
    .Add Name:="CustomString", _
        LinkToContent:=False, _
        Type:=msoPropertyTypeString, _
        Value:="This is a custom property."
    .Add Name:="CustomDate", _
        LinkToContent:=False, _
        Type:=msoPropertyTypeDate, _
        Value:=Date
End With

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>