Setting "Bookmark" text in Text Form Field Options dialog

  • Thread starter Thread starter William Bartusek
  • Start date Start date
W

William Bartusek

I can add a bookmark for a text field on a Word document
using the following code:

ActiveDocument.FormFields(amtIndex).Range.Bookmarks.Add _
Name:=str, _
Range:=ActiveDocument.FormFields(amtIndex).Range

Note: "amtIndex" is a defined integer

However, I can't figure out the code syntax to use that
actually enters the bookmark text in the "Bookmark:" field
in the Text Form Field Options dialog form. "Name" doesn't
work. The other fields, such as TextInput for "Default
number", in the Text Form Field Options dialog have
obvious choices as VBA code objects/data members.
 
Hi William,

The form field already has a bookmark associated with it, so you don't need
to add one. The one you're adding is "on top of" the field, not the one
whose name is shown in the Properties dialog.

To change the name of the associated bookmark, use syntax like

ActiveDocument.FormFields(amtIndex).Name = str

There's an odd situation you can encounter in which the fields don't have a
name, and then VBA has trouble assigning one. See
http://word.mvps.org/FAQs/MacrosVBA/AssignNameToFmFld.htm for a workaround
for that if you need it.
 
When I used the code with .Name=str I kept getting an
error message "Method 'Name' of object 'FormField'
failed", evidently because of the "odd situation you can
encounter in which the fields don't have a
name, and then VBA has trouble assigning one." Using VBA
I was copying then pasting a FormField to create a
duplicate--therefore, the pasted FormField did not have a
name.
 
Back
Top