field code names

  • Thread starter Bshawn via OfficeKB.com
  • Start date
B

Bshawn via OfficeKB.com

I have a document with several of the same types of fields. Is there a way
to name fields other than by their number? The only way I know to select a
certain field is ActiveDocument.Fields(1), ActiveDocument.Fields(2).

Thank you very much!
 
D

Doug Robbins - Word MVP

You could assign a bookmark name to the field. Then you would use

ActiveDocument.Bookmarks("Bookmarkname").Range.Fields(1)

to refer/work with the field.

For example if you had a { QUOTE "Something" } field to which you assigned
the bookmark name of "Test", the following code would change the field to
{ QUOTE "Anything" }

With ActiveDocument.Bookmarks("Test").Range.Fields(1)
.Code.Text = Replace(.Code.Text, "Something", "Anything")
.Update
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
P

Peter Jamieson

I doubt if there is a way that would not make document maintenance
harder. Assuming you have complete control over document content, you
might conceivably bookmark every field and reference them indirectly
using something like
Activedocument.Bookmarks("thebookmarkname").range.fields(1)
but I suspect that not all bookmarks would survive field updating, and
if you were using nested fields I'm not sure if fields(1) would always
get you the field you expected, nor whether this would work unless you
first made all fields visible.

Otherwise, I guess you're stuck with the usual
a. choose the range you're interested in (somehow or other, e.g.
starting with the Selection)
b. iterate through the fields in that range looking for the thing you
want.

Peter Jamieson

http://tips.pjmsn.me.uk
 

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