DocumentProperties.Add 方法 (Office)

创建新的自定义文档属性。 你只可向自定义 DocumentProperties 集合添加新的文档属性。

语法

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

expression:必需。 一个代表 DocumentProperties 对象的变量。 自定义 DocumentProperties 对象。

参数

名称 必需/可选 数据类型 说明
Name 必需 String 属性的 Name 字符串。
LinkToContent 必需 Boolean 指定 LinkToContent 属性是否链接至容器文档的内容。 如果此参数为 True,则 LinkSource 参数是必需的,如果它为 False,则 Value 参数是必需的。
Type 可选 Variant Type 属性的数据类型。 可以是以下 MsoDocProperties 常量之一:msoPropertyTypeBooleanmsoPropertyTypeDatemsoPropertyTypeFloatmsoPropertyTypeNumbermsoPropertyTypeString
Value 可选 Variant Value 属性的数据值,如果它未链接至容器文档的内容。 值将被转化以匹配 Type 参数指定的数据类型,如果无法转化,则会出现错误。 如果 LinkToContentTrue,则参数将被忽略,并且在容器应用程序更新链接的属性值(通常是保存文档时)之前,将会为新的文档属性分配默认值。
LinkSource 可选 Variant 如果 LinkToContentFalse,则忽略。 LinkSource 属性的来源。 此容器应用程序确定可使用的来源链接类型。 例如,DDE 链接将使用“Server|Document!Item”语法。

备注

如果在 DocumentProperties 集合中添加了自定义文档属性,该属性链接到 Office 文档中指定的值,则必须保存文档以查看 DocumentProperty 对象的更改。

示例

本示例设计为在 Word 中运行,它将向 DocumentProperties 集合中添加三个自定义文档属性。

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

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。