Home |
Search |
Today's Posts |
#1
|
|||
|
|||
get mailmerge fields in an IF formula
Hi,
I use Word.MailMerge.Fields to get the set of fields in a document. One of the fields is an IF formula that contains a couple of mailmerge fields. When I loop through the fields, for each field, I use Word.MailMergeField.Code.Text to get the field code. When it loops to the IF statement, I get the whole if statement instead of the fields contained in the if statement as the field code. Is there a way to get the fields contained in an if statement besides string parsing? Thanks, Gary |
#2
|
|||
|
|||
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 "Gary Wu" wrote in message oups.com... Hi, I use Word.MailMerge.Fields to get the set of fields in a document. One of the fields is an IF formula that contains a couple of mailmerge fields. When I loop through the fields, for each field, I use Word.MailMergeField.Code.Text to get the field code. When it loops to the IF statement, I get the whole if statement instead of the fields contained in the if statement as the field code. Is there a way to get the fields contained in an if statement besides string parsing? Thanks, Gary |
#3
|
|||
|
|||
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! |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Custom Fields in Word 2002 (XP) | Microsoft Word Help | |||
Can't find locked fields | Mailmerge | |||
mailmerge more than 256 fields using quatrro as a source | Mailmerge | |||
Using MAILMERGE fields within HYPERLINK fields for Merge to Email | Mailmerge | |||
posting data from text input fields to fields later in document | Microsoft Word Help |