Class FormField (Word VBA)

The class FormField represents a single form field. The FormField object is a member of the FormFields collection.

The main procedures of class FormField are Copy, Delete, Select and FormFields.Add

Set

To use a FormField class variable it first needs to be instantiated, for example

Dim ffd as FormField
Set ffd = ActiveDocument.FormFields(Index:=1)

The following procedures can be used to set variables of type FormField: Next, Previous, FormFields.Add, FormFields.Item, Document.FormFields, Range.FormFields and Selection.FormFields

For Each

Here is an example of processing the FormField items in a collection.

Dim ffd As FormField
For Each ffd In ActiveDocument.FormFields
	ffd.CalculateOnExit = False
Next ffd

Methods

These are the main methods of the FormField class

Copy - Copies the specified form field to the Clipboard.

ActiveDocument.FormFields(1).Copy

Delete - Deletes the specified form field.

ActiveDocument.FormFields(1).Delete

Select - Selects the specified object.

ActiveDocument.FormFields(1).Select

FormFields.Add - Returns a FormField object that represents a new form field added at a range.

Dim ffd As FormField
Set ffd = ActiveDocument.FormFields.Add(Range:=, Type:=wdFieldAddin)

Properties

CalculateOnExit true if references to the specified form field are automatically updated whenever the field is exited.

ActiveDocument.FormFields(1).CalculateOnExit = True

CheckBox returns a CheckBox object that represents a check box form field.

Dim cbxCheckBox As CheckBox
Set cbxCheckBox = ActiveDocument.FormFields(1).CheckBox

DropDown returns a DropDown object that represents a drop-down form field.

Dim ddnDropDown As DropDown
Set ddnDropDown = ActiveDocument.FormFields(1).DropDown

Enabled true if a form field is enabled.

ActiveDocument.FormFields(1).Enabled = True

EntryMacro returns or sets an entry macro name for the specified form field (CheckBox, DropDown, or TextInput).

ActiveDocument.FormFields(1).EntryMacro =

ExitMacro returns or sets an exit macro name for the specified form field (CheckBox, DropDown, or TextInput).

ActiveDocument.FormFields(1).ExitMacro =

HelpText returns or sets the text that's displayed in a message box when the form field has the focus and the user presses F1.

ActiveDocument.FormFields(1).HelpText =

Name returns or sets the name of the specified object.

ActiveDocument.FormFields(1).Name =

Next returns the next form field in the collection.

Dim ffdNext As FormField
Set ffdNext = ActiveDocument.FormFields(1).Next

OwnHelp specifies the source of the text that's displayed in a message box when a form field has the focus and the user presses F1.

ActiveDocument.FormFields(1).OwnHelp = True

OwnStatus specifies the source of the text that's displayed in the status bar when a form field has the focus.

ActiveDocument.FormFields(1).OwnStatus = True

Parent returns an object that represents the parent object of the specified FormField object.

Dim objParent As Object
Set objParent = ActiveDocument.FormFields(1).Parent

Previous returns the previous form field in the collection.

Dim ffdPrevious As FormField
Set ffdPrevious = ActiveDocument.FormFields(1).Previous

Range returns a Range object that represents the portion of a document that is contained within the form field.

Dim rngRange As Range
Set rngRange = ActiveDocument.FormFields(1).Range

Result returns a String that represents the result of the specified form field.

ActiveDocument.FormFields(1).Result =

StatusText returns or sets the text that is displayed in the status bar when a form field has the focus.

ActiveDocument.FormFields(1).StatusText =

TextInput returns a TextInput object that represents a text form field.

Dim titTextInput As TextInput
Set titTextInput = ActiveDocument.FormFields(1).TextInput

Type returns the field type.

Dim wftType As WdFieldType
wftType = ActiveDocument.FormFields(1).Type

FormFields.Count returns a Long that represents the number of fields in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.FormFields.Count

FormFields.Parent returns an object that represents the parent object of the specified FormFields object.

Dim objParent As Object
Set objParent = ActiveDocument.FormFields.Parent

FormFields.Shaded true if shading is applied to form fields.

ActiveDocument.FormFields.Shaded = True