Loop with renaming FormFields

J

Jan DOUMEN

Hi,

I'm been struggling with a renaming formfields problem. There are
numerous post available on how to rename formfields, with or without
empty bookmark. I've merged two sample codes that people posted to
result in:

For Each oFormField In ActiveDocument.FormFields
If oFormField.Range.InRange(oTable.Range) Then
oFormField.Range.Select
With Dialogs(wdDialogFormFieldOptions)
.Name = "blah_" & i
.Execute
End With
i = i + 1
End If
Next oFormField

When executing this code from a button in a word form, I end up in an
endless loop in the first cell of the table that contains a formfield.
He is selecting the first formfield over and over again. When I halt
the code, the bookmark is something like "blah_39", so it is counting
up nicely.

I had first tried renaming the formfields without the dialogs trick,
in the most simple way:

oFormField.Name = "blah_" & i

I end up with the famous Runtime error "2147467259" : method Name of
object FormField failed.

Funny enough

oFormField.Result = "blah_" & i

is working nicely.

Any more hints on how to rename all formfields in a table?

Thanks in advance,

Greetings,
 
W

Word Heretic

G'day (e-mail address removed) (Jan DOUMEN),

the

For k= ActiveDocument.FormFields.Count to 1 step -1

approach may work :)

(e-mail address removed) (Jan DOUMEN) was spinning this yarn:
Hi,

I'm been struggling with a renaming formfields problem. There are
numerous post available on how to rename formfields, with or without
empty bookmark. I've merged two sample codes that people posted to
result in:

For Each oFormField In ActiveDocument.FormFields
If oFormField.Range.InRange(oTable.Range) Then
oFormField.Range.Select
With Dialogs(wdDialogFormFieldOptions)
.Name = "blah_" & i
.Execute
End With
i = i + 1
End If
Next oFormField

When executing this code from a button in a word form, I end up in an
endless loop in the first cell of the table that contains a formfield.
He is selecting the first formfield over and over again. When I halt
the code, the bookmark is something like "blah_39", so it is counting
up nicely.

I had first tried renaming the formfields without the dialogs trick,
in the most simple way:

oFormField.Name = "blah_" & i

I end up with the famous Runtime error "2147467259" : method Name of
object FormField failed.

Funny enough

oFormField.Result = "blah_" & i

is working nicely.

Any more hints on how to rename all formfields in a table?

Thanks in advance,

Greetings,

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email: (e-mail address removed)
Products: http://www.geocities.com/word_heretic/products.html
Spellbooks: 728 pages of dump left and dropping...

The VBA Beginner's Spellbook: For all VBA users.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top