Object Model Reference : Classes : D : DataItems : Methods : DataItems.Add |
Function Add(DataField As DataField, [Value As Variant]) As DataItem
Member of DataItems
The Add method adds a new data field to a shape and optionally specifies its value.
If a data field is not a document default and is empty for the current shape, it is not listed in the shapes DataItems collection that is, it is not returned by the ObjectData property. In this case, the Add method is the only way to set some value to that field. If the field is already listed in the collection, the Add method returns the reference to its data item.
Parameter
|
Description
|
DataField
|
Specifies the data field. A data field is a single property or value associated with a DataItem object.
|
Value
|
Associates a value for the new data field. This parameter is optional.
|
The following VBA example adds a new data field with name Weight to the active shape and specifies its value as 6. The Weight field must already be defined in the current document.
Sub Test() |
Dim df As DataField |
Dim di As DataItem |
Set df = ActiveDocument.DataFields.Add("Weight1") |
Set di = ActiveShape.ObjectData.Add(df) |
di.Value = 6 |
End Sub |
The following VBA example adds a data field and specifies its value as 10.
Sub Test() |
Dim df As DataField |
Dim di As DataItem |
Set df = ActiveDocument.DataFields.Add("Weight2") |
Set di = ActiveShape.ObjectData.Add(df, 10) |
MsgBox "The new value of '" & df.Name & "' field is " & di.FormattedValue |
End Sub |
Copyright 2013 Corel Corporation. All rights reserved.