Is it possible to use conditional formatting in Microsoft Word 2007 Mail merge? I would like it to color the font, depending on the field value, for instance:

  • if "Priority" field equals 1, color the font to red
  • if "Priority" field equals 2, color the font to yellow
  • if "Priority" field equals 3, color the font to green

I've tried using the "Rules" -> "If... Then... Else" and this could probably work, but creating rules using it is a nightmare.... Is there a better way?


Using If..Then..Else is the right start as it inserts an IF field into the document which is what you need, however the dialog which comes up isn't powerful enough to do this kind of thing so you will need to edit the IF fields manually in the document.

What you will need to have is IF fields which compare the value of the field and will display the field with desired color for the appropriate value. Don't forget the MERGEFORMAT switch so that this color is passed on to the merged text.

enter image description here

  • If you want to apply the specified formatting (i.e. as applied to the first characte(s) in the field code, it's the \*Charformat switch you really need. – user181946 Feb 23 '14 at 16:17
  • @bibadia, Either one will work. – Adam Feb 23 '14 at 22:48
  • I doubt if it matters to the OP, but strictly speaking there is a difference. With \*MERGEFORMAT at the end of the outer field, if you insert the result of another field (say, one which has 3 words in each row) instead of each { MERGEFIELD Priority *MERGEFORMAT }, update the fields, then manually change the colour of the middle word to blue, that \*MERGEFORMAT will result in the second word being output as blue in all the records. That's what \*MERGEFORMAT was for. Using 3 \*MERGEFORMATs, three (not four) \*CHARFORMATs, or no switches, all impose the specified colour. I think! – user181946 Feb 24 '14 at 9:50
  • 1
    @bibadia, You maybe right there. I did toss up whether to exclude those last MERGEFORMATS as they didn't look like they belonged but I left them there anyway, as you say it's better they are removed. I suppose if the entire field code is formatting and not just the field code then neither switch needs to be used. – Adam Feb 24 '14 at 12:32

Normally you would need the { IF } as suggested by Adam, or you can use separate IF fields rather than nested ones if the test values are mutually exclusive.

Either way, trying to insert nested fields using the built-in dialogs can be difficult. It's usually simpler to work with the field code shortcut keys and enter them manually - on WIndows Word, ctrl-F9 to insert a pair of the special field code braces, alt-F9 to toggle between field code view and results view, F9 to update selected fields and so on.

In the specific case where there are three values to test, the text to be coloured is short and contains no single quote characters, then you could consider using something like this:

{ ={ MERGEFIELD Priority }-2 \#"'priority 3 text';'priority 1 text';'priority 2 text'" }

Then you apply the appropriate colour to each text.

The length limitation is that the text between the "" cannot exceed 64 characters.

You can bring the text in from a merge field by nesting the appropriate merge field, but the same limitations on single quote characters and total length apply.

  • Interesting way to tackle this however trying that field code I get a syntax error. Can you double check it? – Adam Feb 24 '14 at 14:31
  • @adam - thanks - yes, it was missing a backslash. – user181946 Feb 24 '14 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.