1

I have two defined Styles in Word 2016 that are used for starting sections. They are called Header_num_1 and Header_num_2. Now the header is done like this

{ STYLEREF Header_num_1 \* MERGEFORMAT }
{ STYLEREF Header_num_2 \* MERGEFORMAT }

This lets the section titles appear in the header, e.g.

Introduction
Legal Issues

I also have empty pages that do not have section titles. In this case the header is repeated which I do not want. Any idea on how to insert a condition that empty pages do not get a header? Introducing a new section for empty pages would be an option but I wonder if there is something like an if command in VBA.

1

I don't think there is a single, easily automated way to do this, but depending on exactly how these empty pages are arising, you could consider one of the following...

Once your pagination is known, get Word to insert a completely blank page at the appropriate point by deliberately inserting an Odd page break or an Even page break as appropriate.

Insert your own section breaks to create a one-page section and remove the STYLEREF fields from the header(s) in that section. I suspect this is actually the simplest and most automatable general-purpose approach (although it makes section creation a bit more complicated) because you could consider writing VBA to detect empty pages and repalce them by empty sections.

If you can put something on each empty page (i.e. the pages aren't truly empty, and you either manually ensure that that something does not move to another page), then you could consider putting the following nested field code somewhere in the page

{ SEQ "blanks{ SECTION }p{ PAGE }" \r1\h }

Then in the header, use

{ IF { SEQ "blanks{ SECTION }p{ PAGE }" \c = 0 "{ STYLEREF Header_num_1 \*MERGEFORMAT }
{ STYLEREF Header_num_2 \*MERGEFORMAT }" }

As usual, all the {} have to be the special field code brace pairs that you can insert in Windows Word using ctrl-F9.

In this case, you will need to ensure that all the fields are updated before Word is likely to get the headers correct. Also, Word doesn't particularly 'like' conditionals in headers/footers and does not always display correct values while you are editing.

This only works because for a sequence X, { SEQ X \c } has a value (it is 0) even if there are no { SEQ } fields in the document to set that value. So if for example you need section 3, page 4 to be blank, the field code in the body uses

{ SEQ "blanks{ SECTION }p{ PAGE }" \r1\h }

i.e.

{ SEQ "blanks3p4" \r1\h }

In the header, the value of the SEQ sequence "blanks3p4" is only tested on that page. On the previous page, Word will look for the value of blanks3p3, which will be 0.

I am not sure this works for all the formats of page numbering you could possibly have (some may result in invalid sequence names), but is probably the most general format you could use. If you can rely on straightforward page numbering (e.g. a single sequence numbered 1,2,3.. then you can simplify the name to, say "blank{ PAGE }"

| improve this answer | |

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.