Share via

Conditional header selection

Anonymous
2018-01-07T15:39:33+00:00

Dear community, 

I would like to create a conditional styleref for the header.

The condition is as follows, if a Heading 4 does not exist within the section, then use another one(e.g. Heading 2).

I have tried to figure out myself writing this conditional script:

{IF{STYLEREF "Heading 4"}= "Error!*" {STYLEREF "Heading 2"} {STYLEREF "Heading 4"}}

But it does not work.

Where is my mistake:

Is there some important spacing, special bracketing and etc.?

Thank you.

BR,

Mihail

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Stefan Blom 342.4K Reputation points MVP Volunteer Moderator
2018-01-07T23:40:39+00:00

Doug, maybe I'm missing something, but I would expect your nested fields to work only if Heading 4 is missing completely from the document?

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2018-01-07T23:34:39+00:00

Did you use CTRL+F9 to insert each pair of field delimiters { }?

The following does work here

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Stefan Blom 342.4K Reputation points MVP Volunteer Moderator
2018-01-07T23:24:27+00:00

The STYLEREF field would only display an error if there is no paragraph at all using the referenced style, so the conditional field isn't going to work.

What you can do is create a character style; in sections where Heading 4 exists, apply the character style to the Heading 4 paragraph. In each section where there is no Heading 4, apply the character style to the appropriate Heading 2 paragraph instead. This would be a "semi-automatic" solution, of course, and in a long, complex document it may be difficult to maintain.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2018-01-08T09:12:21+00:00

    Dear Stefan, Doug,

    Everything works!

    The first mistake was that I have considered this as a script, but this works more like text replacing.

    So, the mistake was exactly because of this.. There should be no any extra spacing in {STYLEREF "Heading 4" ...}, otherwise it cannot 

    coincide with the error messaging.

    Thank you and wish you good time!

    Was this answer helpful?

    0 comments No comments