There are at least two collections: fields, and mailmerge fields. Not all
fields are mailmerge fields. If, for example, your IF field looks like
{ IF { MERGEFIELD a } = 0 "{ MERGEFIELD b }" "{ MERGEFIELD c }" }
then your iteration or MailMergeFields would give you
IF MERGEFIELD a = 0 " MERGEFIELD b " " MERGEFIELD c "
MERGEFIELD a
MERGEFIELD b
MERGEFIELD c
whereas
{ IF { MERGEFIELD a } = 0 "{ b }" "{ c }" }
would give you
IF MERGEFIELD a = 0 " b " " c "
MERGEFIELD a
If you use the ActiveDocument.Fields collection (notice that the Field type
is different from the MailMergeField type), you will see the same result for
the first IF statement but
IF MERGEFIELD a = 0 " b " " c "
MERGEFIELD a
b
c
for the second.
Peter Jamieson
> Hi,
>
[quoted text clipped - 9 lines]
> Thanks,
> Gary
Gary Wu - 02 Feb 2005 19:21 GMT
Peter, thank you very much! With the information you provided, I solved
my problem. What I wanted to achieve is to replace mailmerge fields in
one application with corresponding mailmerge fields in another and at
the same time reserve all the logic in formulas.
So, what I did to achieve that is for each mailmerge field, I check its
type like this
Word.MailMergeField field = ... //a reference to a mailmerge field
if (field.Type == Word.WdFieldType.wdFieldMergeField)
{
//replace the field with a corresponding field.
}
Formulas like an IF statement is of type wdFieldFormula and mailmerge
fields contained in an IF statement is of type wdFieldMergeField. So
with the above code, I can replace only mailmerge fields while keeping
the logic in formulas intact.
Thanks Peter again for your helpful information!