Table of contents
TOC
Collapse the table of content
Expand the table of content

DocumentProperties.Add Method (Office)

office 365 dev account|Last Updated: 10/19/2017
|
2 Contributors

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

NameRequired/OptionalData TypeDescription
NameRequiredStringThe string of the Name of the property.
LinkToContentRequiredBooleanSpecifies 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.
TypeOptionalVariantThe data type of the Type property. Can be one of the following MsoDocProperties constants: msoPropertyTypeBoolean, msoPropertyTypeDate, msoPropertyTypeFloat, msoPropertyTypeNumber, or msoPropertyTypeString.
ValueOptionalVariantThe 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).
LinkSourceOptionalVariantIgnored 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


See also

Concepts

Other resources

© 2018 Microsoft