Hi 4tis,
i tried this code based on what you wrote to me :
Dim ind As Integer
ind = ActiveDocument.Variables("myPrimaryFooterField").Index
MsgBox (ind)
Set rng = ActiveDocument.Fields(ind).Result
rng.Font.name = "Arial"
but then, when i run this code i get an error says :
run-time error '5941':
the requested number of the collection does not exist.
In Word, the fields in a document are indexed by the order in
which they appear in the document. There is no relationship
whatsoever to the Index property of the Variables collection. Word
has over 100 different kinds of fields, not just docVar fields.
If you have no other way of identifying the field, and you aren't
trying to format it at the time the field is being inserted, then
you probably have no choice but to loop through the entire
collection of fields in the Word document, testing the identifier
for each field. For example, something along these lines
For each fld in ActiveDocument.Fields
If Instr(fld.Code, "myPrimaryFooterField") <> 0 Then
Set rng = ActiveDocument.Fields(ind).Result
rng.Font.name = "Arial"
End If
Next
If you need to do this a lot then it would probably make sense to
loop through the fields once, setting up a custom collection with
an index on the doc variable's name so that you can access them
more quickly...
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17
2005)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail