Word – Behavior When Pasting Sections

Note: This article’s solution was tested in Word 2016.

I recently discovered a curious behavior in Word when trying to solve a vexing problem with my firm’s third-party Word template add-in.

What happens when you paste in a section, including its section break? (not using the unformatted text option.)

The section you paste in

For starters, the section that you paste in should retain in the destination document the section properties that it had in its source document. The section properties generally include the things under the Layout > Page Setup group in the ribbon. It also includes the section’s headers and footers, unless the headers/footers are being replicated from a previous section.

How it affects other sections

What this post is more concerned with is what happens to the other sections in your destination document, specifically the headers and footers. Depending on settings in the headers and footers of your destination document, the sections following the pasted-in section may pick up the headers and footers of the pasted-in section.

Whether they do or not depends on a setting in each header and footer, which is the “Link to Previous” toggle button you see when you go into a header or footer.

It’s important to know, as I’ve stated (blog post on hidden headers/footers), that each section in a Word document has three headers and three footers. Each of those headers and footers has its own independent Link to Previous setting. So if the First Page header has Link to Previous turned on, it will replicate the First Page header of the previous section. Same for the Primary header, etc.

This setting comes into play when you do the paste. So if you want the new headers to propagate to the following section, make sure it is on in the headers/footers of the destination section.

Complication with the document’s first section

But there is a complication involving the first section in the destination document. The first section has no previous section, so if you look at the Link to Previous button, it is disabled, of course. You might think the setting is off, but no, the button is disabled because it’s irrelevant.

So what happens when you paste a section into the first section?

This is the strange behavior.

If there is no content in the first section headers/footers, then they will pick up from the pasted section, as if Link to Previous is on. But if there is already content in the headers/footers, they will not pick up, as if Link to Previous is off.

This seems like a sensible enough approach. To my knowledge it is not documented.

How I saved the firm

How did this relate to the vexing problem we were having?

The templates we were working with were pleadings, and one of our requirements for these particular templates was to have a TOC and a TOA section included. Our vendor’s code runs through numerous complicated procedures when initializing a pleading, to insert a caption, etc. They also have a standalone procedure to add TOC and TOA sections.

Our problem was that the main body section was getting the TOA section’s headers.

The template starts with only the main body section—no cover page or TOC/TOA. The rest is added by the setup code. What I discovered during testing, by observing the undo/redo history, was that the cover, TOC and TOA sections were apparently being added through a paste operation in code. (The add-in is compiled VSTO, and I did not have access to the vendor’s code. But the undo history had a “VBA.Paste” at the point where the added sections appeared.)

So, I knew about Link to Previous and I started experimenting, wondering what would happen to the first section. I thought it would be odd that Link to Previous would be true on the first section, but experimenting with blank documents confirmed that it was, or acted that way.

I then put some content into the headers and saw the opposite result. So the solution to our problem was simply to put some content—a space character—into the headers of the templates.

Pleadings getting TOA headers in the main body was completely unacceptable. However, the same pleading templates had worked previously. Apparently, the vendor’s code corrected the main body headers after the paste operation, and something in the new build was breaking that. My initial solution was to write VBA to do what supposedly the vendor’s code had done previously—unlink and clear the headers, but this was complicated and less than satisfactory. I kept going back to it and trying to figure something out. Then I had the long night looking at the undo history and came up with the space character solution.

My recent employment has included a lot of this kind of detective work. It’s hard, hair-pulling stuff, but it’s great to isolate a problem and solve it.