Add Method (Fields Collection)

Applies To

Fields collection object.

Description

Adds a field at the specified range.

Syntax

expression.Add(Range, Type, Text, PreserveFormatting)

expression Required. An expression that returns a Fields object.

Range Required Range. The range where you want to add the field. If the range isn't collapsed, the field replaces the range.

Type Optional Variant. The kind of field to be added. Can be one of the following WdFieldType constants

  • wdFieldAddin
  • wdFieldAdvance
  • wdFieldAsk
  • wdFieldAuthor
  • wdFieldAutoNum
  • wdFieldAutoNumLegal
  • wdFieldAutoNumOutline
  • wdFieldAutoText
  • wdFieldAutoTextList
  • wdFieldBarCode
  • wdFieldComments
  • wdFieldCompare
  • wdFieldCreateDate
  • wdFieldData
  • wdFieldDatabase
  • wdFieldDate
  • wdFieldDDE
  • wdFieldDDEAuto
  • wdFieldDocProperty
  • wdFieldDocVariable
  • wdFieldEditTime
  • wdFieldEmbed
  • wdFieldEmpty
  • wdFieldExpression
  • wdFieldFileName
  • wdFieldFileSize
  • wdFieldFillIn
  • wdFieldFootnoteRef
  • wdFieldFormCheckBox
  • wdFieldFormDropDown
  • wdFieldFormTextInput
  • wdFieldFormula
  • wdFieldGlossary
  • wdFieldGotoButton
  • wdFieldHTMLActiveX
  • wdFieldHyperlink
  • wdFieldIf
  • wdFieldImport
  • wdFieldInclude
  • wdFieldIncludePicture
  • wdFieldIncludeText
  • wdFieldIndex
  • wdFieldIndexEntry
  • wdFieldInfo
  • wdFieldKeyWord
  • wdFieldLastSavedBy
  • wdFieldLink
  • wdFieldListNum
  • wdFieldMacroButton
  • wdFieldMergeField
  • wdFieldMergeRec
  • wdFieldMergeSeq
  • wdFieldNext
  • wdFieldNextIf
  • wdFieldNoteRef
  • wdFieldNumChars
  • wdFieldNumPages
  • wdFieldNumWords

  • wdFieldOCX
  • wdFieldPage
  • wdFieldPageRef
  • wdFieldPrint
  • wdFieldPrintDate
  • wdFieldPrivate
  • wdFieldQuote
  • wdFieldRef
  • wdFieldRefDoc
  • wdFieldRevisionNum
  • wdFieldSaveDate
  • wdFieldSection
  • wdFieldSectionPages
  • wdFieldSequence
  • wdFieldSet
  • wdFieldSkipIf
  • wdFieldStyleRef
  • wdFieldSubject
  • wdFieldSubscriber
  • wdFieldSymbol
  • wdFieldTemplate
  • wdFieldTime
  • wdFieldTitle
  • wdFieldTOA
  • wdFieldTOAEntry
  • wdFieldTOC
  • wdFieldTOCEntry
  • wdFieldUserAddress
  • wdFieldUserInitials
  • wdFieldUserName

The default value is wdFieldEmpty.

Text Optional Variant. Additional text needed for the field. For example, if you want to specify a switch for the field, you would add it here.

PreserveFormatting Optional Variant. True to have the formatting that's applied to the field preserved during updates.

Remarks

You cannot insert some fields (such as wdFieldOCX and wdFieldFormCheckBox) by using the Add method of the Fields collection. Instead, you must use specific methods such as the AddOLEControl method and the Add method for the FormFields collection.

See Also

Fields property.

Example

This example inserts a USERNAME field at the beginning of the selection.

Selection.Collapse Direction:=wdCollapseStart
Set myField = ActiveDocument.Fields.Add(Range:=Selection.Range, _
    Type:=wdFieldUserName)
This example inserts a LISTNUM field at the end of the selection. The starting switch is set to begin at 3.

Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldListNum, _
    Text:="\s 3"
This example inserts a DATE field at the beginning of the selection and then displays the result.

Selection.Collapse Direction:=wdCollapseStart
Set myField = ActiveDocument.Fields.Add(Range:=Selection.Range, _
    Type:=wdFieldDate)
MsgBox myField.Result