Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / February 2005

Tip: Looking for answers? Try searching our database.

get mailmerge fields in an IF formula

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary Wu - 02 Feb 2005 01:32 GMT
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
Peter Jamieson - 02 Feb 2005 09:46 GMT
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!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.