Share via

StyleRef Heading 3 in Header issue

Anonymous
2024-04-23T17:30:34+00:00

Hello

I am writing this here as I have an issue with a Document.

In the Header and Footer of the Document I display some information such as page Numbers as well as Displaying the chapter etc.

The Document with the Headings is structured as follows:

  1. Document title Heading and TOC 1
    1. Work 1 Heading and TOC 2
      1. Chapter 1 Heading and TOC 3
      2. Chapter 2 Heading and TOC 3
    2. Work 2 Heading and TOC 2
    3. Work 3 Heading and TOC 2
      1. Chapter 1 Heading and TOC 3
      2. Chapter 2 Heading and TOC 3

I want to display in the Header in the middle  "STYLEREF  "Heading 2"  \* MERGEFORMAT" which works just fine and shows the Work according to what is on the page.

On the right side I display " STYLEREF  "Heading 3"  \* MERGEFORMAT". Here I want to show the Chapter to which the actual page belongs to, the issue now being that if I have Work part like Work 2 which has no separate chapters it will display still chapter 2 from Work 1.

Can this be avoided without using multiple different headers?

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

7 answers

Sort by: Most helpful
  1. Charles Kenyon 167.8K Reputation points Volunteer Moderator
    2024-04-23T19:37:37+00:00

    See Useful StyleRef tricks by Suzanne Barnhill, MVP.

    You would want to place a blank paragraph in Heading 3 at the beginning of the part where you do not want that heading to display.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Charles Kenyon 167.8K Reputation points Volunteer Moderator
    2024-04-29T19:20:24+00:00

    I've updated my StyleRef Field tutorial document to demonstrate how this works.

    The demonstration of a blank paragraph in the target style is shown on the last page (4) of the macro-free document.

    Here is a temporary link to the tutorial document: https://www.dropbox.com/scl/fi/ajasstpl2084qgxm1tfjj/StyleRefTutorial.zip?rlkey=plmce3exjbx4pizpd77ndd4de&dl=0 The permanent home will be on my downloads page at: StyleRef Field Tutorial.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Charles Kenyon 167.8K Reputation points Volunteer Moderator
    2024-04-28T23:49:27+00:00

    Try following my suggestion.

    A blank paragraph formatted with Heading 3 style at the beginning of sections where you do not have text that uses that style. The StyleRef field will show up as blank.

    I've updated my StyleRef Field tutorial document to demonstrate how this works.

    The demonstration of a blank paragraph in the target style is shown on the last page (4) of the macro-free document.

    Here is a temporary link to the tutorial document: https://www.dropbox.com/scl/fi/ajasstpl2084qgxm1tfjj/StyleRefTutorial.zip?rlkey=plmce3exjbx4pizpd77ndd4de&dl=0 The permanent home will be on my downloads page at: StyleRef Field Tutorial.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  5. Anonymous
    2024-04-23T18:04:17+00:00

    Hi I’m a Microsoft user like yourself and I will try to help you as best as I can today.

    1. Use Conditional Fields The idea here is to conditionally display the chapter name only when the current page actually belongs to a chapter within the current work (Heading 2).
    2. Setting Up the Fields You should use the IF field to check if the current chapter (Heading 3) is associated with the current work (Heading 2). This can be tricky because Word does not directly support checking the relationship between different heading levels directly in fields. However, you can work around this by using a bookmarking strategy if straightforward STYLEREF usage fails.

    Basic Field Insertion First, try to insert this basic field combination:

    { STYLEREF "Heading 3" \* MERGEFORMAT } As you've noticed, this works until you hit a section like Work 2 which doesn't have chapters.

    Adding the Conditional IF Statement You might attempt to use an IF statement to check if the current Heading 3 belongs to the current Heading 2, but directly referencing one heading's relationship to another isn't straightforward in Word fields. Instead, you can add a check to see if Heading 3 is empty:

    { IF { STYLEREF "Heading 3" \* MERGEFORMAT } <> "" "{ STYLEREF "Heading 3" \* MERGEFORMAT }" ""} This checks if STYLEREF "Heading 3" returns a non-empty string. If true, it displays the chapter; if false, it displays nothing.

    1. Inserting the Field To insert these fields in Word:

    Place your cursor in the header where you want to insert the field. Press Ctrl + F9 to insert a blank field (this will look like { }). Inside the brackets, type your field code. Right-click the field and select “Update Field” or press F9 to update its content.

    1. Testing and Adjusting It’s essential to test different parts of your document to ensure that the headers behave correctly across different sections. If the simple IF condition doesn't work as expected due to complexities in how STYLEREF evaluates context, consider setting up specific bookmarks at each Heading 2 and using those bookmarks to control the display logic more granularly.

    If these suggestions do not work due to these limitations, considering using a VBA (Visual Basic for Applications) script might be necessary to achieve the desired header functionality with more control.

    Hope this helps! Please let us know if you have any questions. Microsoft Support is available for further assistance if the issue persists.

    Best Regards Deeksha

    Was this answer helpful?

    0 comments No comments