Share via

styleref in header conditional logic

Anonymous
2017-05-07T22:36:21+00:00

Hi,

I'm trying to use the styleref field code to dynamically populate a header in a Word template.

My challenge is that the appropriate heading text will be be in one of two styles; depending on the intended audience for the document. How can I have Word look for style1 and if it doesn't find it, look for style2 and use that instead?  

Thanks in advance for your help!

Christa

***Post moved by the moderator to the appropriate forum category.***

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

Paul Edstein 82,861 Reputation points Volunteer Moderator
2017-05-08T04:39:49+00:00

Basically, you'd use a field coded along the lines of:

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

where 'Heading 1' and 'Heading 2' are the Style names.

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.

Was this answer helpful?

5 people found this answer helpful.
0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2017-05-08T23:08:14+00:00

    With the current logic, it doesn't seem to be updating as the styles switch. 

    It's not meant to - the field code supplied addresses only the issue described in your initial post, which was the potential absence of a given style in the document as a whole.

    As for toggling between, styles, you'll have problems with that, since the STYLEREF field inserts a copy of the nearest matching material formatted with the specified style; there is no switch to toggle it on/off if there's content in another Style.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2017-05-08T17:59:21+00:00

    Thank you both for the help. Is there anyway to modify the header logic so it checks and updates on each page? For example, the title for page 1 may use style1 but the title for page 6 might use style2, and then page 10 might switch back to style1. With the current logic, it doesn't seem to be updating as the styles switch.

    Was this answer helpful?

    0 comments No comments
  3. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2017-05-08T06:36:27+00:00

    Oops - of course. Fixed.

    Was this answer helpful?

    0 comments No comments
  4. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2017-05-08T05:53:32+00:00

    Paul of course meant to suggest:

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

    Was this answer helpful?

    0 comments No comments