#1
|
|||
|
|||
IF Statement in Word
Hello, I could use some help please. I have a mail merge template that has a field that references secretaries. I need to replace those secretaries names with their bosses names. We have approximately 20 secretaries.
Is I possible to create an IF statement to do this in Word 2010? An example of what I tried so far and it worked somewhat but it still leaves the secretaries name instead of replacing it with the manager's name, plus I can only do one string . . . and it also changed the font to a smaller font. {IF "Request_Staff_Person" = "Minnie Mouse" "Mickey Mouse"} The results were: Mickey MouseMinnie Mouse. Any help would be appreciated. |
#2
|
||||
|
||||
You can insert a series of conditional fields (noting the reference to MERGEFIELD
{IF { MERGEFIELD "Request_Staff_Person" } = "Minnie Mouse" "Mickey Mouse"}{IF { MERGEFIELD "Request_Staff_Person" } = "Donald Duck" "Another Mouse"}etc Use CTRL+F9 for each bracket pair { } and no spaces between the items; but frankly it might be better if you modified the data source to include the appropriate bosses.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thank you so much, I'll give this a try. Unfortunately, the managers' names are not in our database, and I don't believe there are plans to add them, the best I could do was to modify the source by adding the available field for the secretaries.
One additional question, is there a limit to how many if statements I can run together? |
#4
|
|||
|
|||
This did no work for me.
|
#5
|
|||
|
|||
There is no limit to the number of IF Fields you can have, so long as they are independent (not nested, one inside the other).
|
#7
|
|||
|
|||
thanks for the link, i'll try again. a question, I've not done this before in Word. . . didn't even know it was possible. . . I see {MERGEFIELD ....) is this something I would actually type in before I insert the merge field or is it just indicating that the field should be inserted?
|
#8
|
||||
|
||||
Properly implemented, the field code demonstrated in Graham's post will work. At its simplest, you can use either:
{IF{MERGEFIELD Request_Staff_Person}= "Minnie Mouse" "Mickey Mouse"}{IF{MERGEFIELD Request_Staff_Person}= "Donald Duck" "Another Mouse"} or: {IF«Request_Staff_Person»= "Minnie Mouse" "Mickey Mouse"}{IF«Request_Staff_Person»= "Donald Duck" "Another Mouse"} Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. Likewise, the chevrons (i.e. '« »') are part of the actual mergefields - which you can insert from the 'Insert Merge Field' dropdown (i.e. you can't type or copy & paste them from this message, either). The spaces represented in the field constructions are all required.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
My question is geared more to the actual word "MERGEFIELD" when I insert the merge field into the brackets that I've generated by ctrl9, it inserts the merge field but does not include the word MERGEFIELD nor does it include the format with the double arrows as in this example taken from below: «Request_Staff_Person»
|
#10
|
||||
|
||||
That merely demonstrates the second of the two examples I posted...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
I don't see where my question was answered at all. Thank you anyway.
|
#12
|
||||
|
||||
Did you actually read my reply???
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Yes Macropod, I did read your answer; however, I don't believe you read my question . . . I understood what the previous responses were instructing, what I was saying prior to your last response was that no matter what I did . . . the verbiage MERGEFIELD would not appear when I inserted the field into the formula. It only appeared in my result below after I toggled back and forth twice after inserting the field.
For anyone else please that can help with my formula below, I would appreciate it . . . This is my formula: {IF{MERGEFIELD Request_Staff_Person}= "Mickey Mouse" "Minnie Mouse"} This is the result: Mickey Mouse Minnie Mouse. . . instead of replacing Mickey Mouse with Minnie Mouse it is adding it to the same line. I need to replace the original name with the new . . . not add to it. Many thanks in advance. |
#14
|
|||
|
|||
Quote:
|
#15
|
||||
|
||||
From your description it sounds like you have added the conditional field AFTER the original merge field instead of REPLACING it.
«Request_Staff_Person»{IF{MERGEFIELD Request_Staff_Person}= "Mickey Mouse" "Minnie Mouse"} The field goes INSIDE the conditional field i.e. {IF «Request_Staff_Person»= "Mickey Mouse" "Minnie Mouse"} or with field codes toggled (ALT+F9) {IF{MERGEFIELD Request_Staff_Person}= "Mickey Mouse" "Minnie Mouse"} In the case of the latter all bracket pairs are inserted with CTRL+F9 Or you can insert it from the mailmerge tab of the ribbon (Rules)
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
IF statement in Word VBA | BristolJGM | Word VBA | 2 | 09-16-2017 06:02 AM |
and if statement in word mailmerge | sbye | Mail Merge | 17 | 08-25-2017 09:59 PM |
VBA Word - Find & Apply Styles to Specific Words - Using Case Statement | jc491 | Word VBA | 17 | 12-26-2015 12:25 PM |
Microsoft Word IF statement issues | micro44 | Word | 4 | 10-23-2014 12:10 PM |
Help with IF statement in word 2010 | Mad | Word | 2 | 04-06-2013 06:31 AM |