How to assign a Name to a FormField that doesn't already have a Name, using VBA

Article contributed by Ibby

Unfortunately, although Word VBA Help implies that if you select a FormField, the following ought to work:

Selection.FormFields(1).Name = "myField"

... if the FormField in question does not already have a name, the above code returns an error.

However, the following code does work (without actually displaying the dialog):

With Dialogs(wdDialogFormFieldOptions)
    .Name = "myField"
    .Execute
End With

See also: Getting help with calling Word's built-in dialogs using VBA (and why doing so can be much more useful than you'd think).