Code Property Example

This example displays the field code for each field in the active document.

For Each aField In ActiveDocument.Fields
    MsgBox Chr(34) & aField.Code.Text & Chr(34)
Next aField

This example changes the field code for the first field in the active document to CREATEDATE.

Set myRange = ActiveDocument.Fields(1).Code
myRange.Text = " CREATEDATE "
ActiveDocument.Fields(1).Update

This example determines whether the active document includes a mail merge field named "Title."

For Each aField In ActiveDocument.MailMerge.Fields
    If InStr(1, aField.Code.Text, "Title", 1) Then
        MsgBox "A Title merge field is in this document"
    End If
Next aField