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 / October 2007

Tip: Looking for answers? Try searching our database.

If statement to insert word file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ron40 - 05 Oct 2007 14:51 GMT
I am using mail merge to extract fields from an excel file. What I would like
to do is if one of the fields meets a certain condition I would like to
insert another word file into the document. How would I write that if
statement?
Peter Jamieson - 05 Oct 2007 18:32 GMT
You can try

Suppose your test field is called myfield and you want to compare it with
"abc", and include the document "c:\myfolder\mydoc.doc" if it matches. Then
try

{ IF "{ MERGEFIELD myfield }" = "abc" "{ INCLUDETEXT
"c:\\myfolder\\mydoc.doc" }" "" }

All the {} need to be the special field code braces that you can insert
using ctrl-F9. Everything else is plain text. Not the doubled-up backslashes
(although you can probably use single forward slashes instead).

However, you may find that your included file does not actually update
correctly if you do that, and in many situations it's better if you can
"invert" the nesting so you have something more like

{ INCLUDETEXT "c:\\myfolder\\{ IF "{ MERGEFIELD myfield }" = "abc"
"mydoc.doc" "empty.doc" }" }

where empty.doc is an empty Word doc. However, the problem with /that/ is
that will get an extra paragraph mark - if you don't want it, what you can
do instead is
a. select the complete text of mydoc.doc and use insert|bookmark to insert
a bookmark called "all" (say)
b. select a single point in mydoc.doc and insert a bookmark called "none"
c. use

{ INCLUDETEXT "c:\\myfolder\\mydoc.doc" { IF "{ MERGEFIELD myfield }" =
"abc" "all" "none" } }

Signature

Peter Jamieson
http://tips.pjmsn.me.uk

>I am using mail merge to extract fields from an excel file. What I would
>like
> to do is if one of the fields meets a certain condition I would like to
> insert another word file into the document. How would I write that if
> statement?
 
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.