0
I have a Word template with a special table of contents associated with an "Appendix" paragraph style. Sometimes documents that use the template will use that style and sometimes they don't.
The field to create the table of contents looks like this:
{ TOC \n \h \z \t "Appendix" }
If the document uses the "Appendix" style, I want the table of contents to appear as normal, otherwise I want the word "None" to appear.
Here's a rough (and invalid) idea of what I'm trying to do:
{ IF (STYLEREF "Appendix") "{ TOC \n \h \z \t 'Appendix' }" "None" }
While it looks like if statements are supported in Word fields, I'm not sure how to construct this one (if what I'm trying to do is even possible). The above is not valid.
This worked perfectly. It hadn't occurred to me that field codes could be nested like that. – Scribblemacher – 2016-08-25T11:42:09.223
I marked this as the answer because it does solve the problem. Also, an ideal solution wouldn't be dependent on matching that specific error text; you never know if Microsoft will change it in the future. – Scribblemacher – 2016-08-25T12:15:23.780
Just as a tip; you should show the field-codes, and then put your cursor at the right spot and insert another field-code inside the IF field-code to get the references working. If you type the accolades it won't work! – Kolky – 2018-02-20T13:45:32.840
To make Tanya's answer independent of locale or changes in Microsoft's message text, one might use something like {IF {STYLEREF Appendix}={STYLEREF NotInUse}, "None", etc. Be sure that the style NotInUse does exist, but is not used! – J. B. Hemel – 2019-08-06T10:08:36.010