Category Archives: Tips & Tricks

Excel – Use Grouping to Show Tree Structure

Great tool for data room indexes

The other day at the office, I had an interesting request. An attorney had an Excel index from a data room, and wanted to use Excel’s grouping feature to represent the file/folder structure.

The data room, as is typical, had an index column that used a string concatenated from integers to represent file and folder location. For instance, “1,” “2,” “3” etc. are the top-level folders. “1.1” may be a subfolder or a file under folder 1, etc.:

What the attorney wanted was to have the grouping “plus signs” at each folder level, grouping the files and subfolders below that folder.

I came up with the solution using VBA code and one helpful setting in Excel. First, the setting. Excel by default places the summary rows (i.e., the plus signs) below the detail, or group. In this application, we want the plus signs above the group. To allow this, click the dialog launcher under Data > Outline and uncheck “Summary rows below detail.” This is a worksheet-level setting, so it will stick with your sheet.

Another issue to be aware of: Your index column should be formatted as text, so that, for instance, “1.20” does not come into Excel as “1.2” etc. “1.20” in a data room index means the 20th item under 1, but if your cell is formatted as General, Excel will treat it as a number and drop the insignificant zero.

Also be aware that Excel gives you a maximum of 8 grouping levels, so this solution won’t cover grouping deeper levels than that.

Now for the code. It’s fairly compact and quick to run. It determines the level of the current record by the number of tokens in the index string, then applies logic based on the current record’s relation to what has come before it in the loop, grouping at each level in the tree.

Modern Legal Support provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. Always back up your documents before running any code.

Option Explicit
' Code by Kenneth A. Hester

Sub GroupFoldersByLevel()
    Dim i As Long
    Dim r As Range
    Dim rStart As Range
    Dim rEnd As Range
    Dim foundStart As Boolean
    Dim rngGroup As Range
    Dim level As Long
    Dim maxLevel As Long
    Dim levelAtRow As Long
    Dim indexColumn As Long
    Dim fileFolderColumn As Long
    Dim startRow As Long
    Dim atEndRow As Boolean
    ' ----------------------
    ' set these values based on your worksheet:
    maxLevel = 7
    indexColumn = 1
    fileFolderColumn = 3
    startRow = 3
    ' ----------------------
    For level = 1 To maxLevel
        Debug.Print "Processing level " & CStr(level) & "..."
        foundStart = False
        For i = startRow To ActiveSheet.UsedRange.Rows.Count + 1
            Set r = ActiveSheet.Rows(i)
            atEndRow = (i = ActiveSheet.UsedRange.Rows.Count + 1) ' close off last groups at end row
            ' determine level of current row based on number of tokens in index:
            levelAtRow = UBound(Split(CStr(r.Cells(indexColumn).Value), ".")) + 1
            If levelAtRow <= level Or atEndRow Then
            ' found a file or folder at or above the level
                If Not foundStart Then
                ' then we found the start of a group
                    If levelAtRow = level And Trim$(LCase$(r.Cells(fileFolderColumn).Value)) = "folder" Then
                        ' it's a folder at the level
                        Set rStart = r.Offset(1) ' start grouping the files below the folder
                        foundStart = True
                    End If
                Else ' already found start of the group, so now we found the end
                    Set rEnd = r.Offset(-1)
                    If Not rStart.Row > rEnd.Row Then ' this takes care of empty folders
                        Set rngGroup = Range(rStart, rEnd) ' close the group
                    End If
                    If levelAtRow = level And Trim$(LCase$(r.Cells(fileFolderColumn).Value)) = "folder" Then
                        ' if the end is the start of another folder at the level
                        ' reset the start row
                        Set rStart = r.Offset(1)
                        foundStart = True
                        foundStart = False
                    End If
                    'Exit Sub
                End If
            End If
        Next i
    Next level
    Debug.Print "done."
End Sub

After running the code:

You can download my Excel test file with the code here.

Have fun. Let me know if it works for you.

Kenneth Hester is a Microsoft Office Specialist Master (2013, 2010, 2007, 2003) and a Microsoft Certified Application Developer.

Word – Using Fields to Automate Inline Numbering

In this post, I’ll demonstrate how to automate the numbering of inline lists (lists inside a paragraph). I’ll also explain how to avoid an easy pitfall.

Inline lists

Legal documents often feature numbered lists of items within a paragraph, such as:

2.1 Sale and Purchase. The Seller agrees to (a) ______; (b) ______; and (c) ______.

Usually, these are manually typed, which is usually easy and good enough. If, however, you have a document with lots of these lists, or long lists, and the document is getting edited, you might want to automate the list numbering. The way you do this is with field codes. The question is, which field code to use?

You might think the ListNum field is the answer; however the Seq (Sequence) field is probably the better choice. ListNum can mess up your paragraph outline numbering.

The ListNum field

ListNum uses numbers from the outline that you’re in (unless you choose one of the named lists). So, if you’re in a document with heading numbering like “Article I/1.1/(a)/(i)…”—a common legal outline, and you’re in a level 2 paragraph, a ListNum field will give you “(a)” (the next level) by default. Legal document specialists are accustomed to using ListNum fields to handle one particular situation: where you have a number of lower-level paragraphs, but the first one is joined with the higher-level paragraph, e.g.:

2.1 (a) The Seller agrees…

(b) Seller further agrees…

ListNum is perfect for that one scenario; however, that’s different from our problem, which is independent lists of items within a paragraph. If, say, you wanted to follow your level 2 paragraph with some level 3 paragraphs:

2.1 Sale and Purchase. The Seller agrees to (a) ______; (b) ______; and (c) ______.

(a) The Seller will …

(b) The Purchaser will …

you’d find that your first level 3 paragraph will be numbered (d), not (a), because you’ve already used (a), (b) and (c) from your outline.

Also, if, say, you had used ListNum level 4:

The Seller agrees to (i) ______; (ii) ______; and (iii) ______.

your following level 3 paragraph will be (b), not (a), because in outline logic, you can’t be at level 4 unless you’ve crossed level 3. Using the level 4 ListNum field thus increments the counter on level 3.

Note that although you can manually reset the level 3 paragraph number to (a), you really don’t want to—essentially, this makes a second list, which can lead to unexpected results, especially when the outline numbering is connected to paragraph styles, as is usually the case in legal documents.

You can get away with using ListNum fields, but only if you don’t follow them with lower-level numbered paragraphs.

The Seq field

The Seq field is designed for sequences, which is exactly what we have. It also features a lot of options that make it very powerful. In particular, one option we’ll find convenient is that the sequence can be related to the outline, without using numbers from the outline like ListNum.

You can set up a sequence by going to Insert > Quick Parts > Field:

This brings up the Field dialog. Choose “Seq” from the list. On the right, you can see “SEQ” in the Field codes: text box. We need to give the sequence an identifier (you can have multiple sequences in a document). Let’s just call this one “abc,” so type “abc” next to SEQ.

We’re also going to set a couple of options, so click Options, which brings up the Field Options dialog. On the General Switches tab, under Formatting:, choose “a, b, c, …”, then click the Add to Field button. Under the Field Specific Switches tab, choose “\s” (which causes the sequence numbering to restart after a specified heading level) and click Add to Field. Type “2” after the \s, because we want the sequence to restart with each Heading 2. We end up with this:

You can put spaces around the elements to make it more readable, like I did. Also, you don’t need to go through these dialog boxes. When you get accustomed to working with fields, you will probably find it easier to just insert a basic field, then type the switches etc. inside it.

Click OK in both dialogs and Word puts an automatic “a” in your paragraph. You can type parens around it and copy and paste it, or maybe add it to your building blocks collection (Quick Parts > Save Selection to Quick Part Gallery…) to use it throughout your document. If you add it to your building blocks, you can use it on other documents as well.

Note, remember with fields, you need to update them to see results as you’re working—select all, then F9.

In this way, you’ll have a simple, reliable way to automate your inline lists that won’t mess up your paragraph numbering. You could create another sequence in the same manner for a “(i), (ii), (iii)” sequence, etc.

The Seq field is very powerful, as you will find if you explore its options. It’s one of many powerful field codes used in Word. Understanding and using field codes and switches is part of being a Word expert and practicing the modern approach to legal document support.

For more in-depth information from Microsoft, see these articles:

Kenneth Hester is a Microsoft Office Specialist Master (2013, 2010, 2007, 2003) and a Microsoft Certified Application Developer.

Word – Understanding the Table of Authorities Feature

Note: This article applies to Word versions 2007 to 2013.

Skip to:

Word TOAs: Overview

As a lawyer or other legal professional, you may be reluctant to mark your briefs for tables of authorities, thinking it’s difficult. In actuality, it’s pretty easy, and anyone who can understand a brief and has some basic computer skills can do it.

Microsoft Word’s TOA feature reflects the concepts used in citing authorities—the full, well-formed citation, a short form of the cited authority, and a category to place the authority in.

The tools for marking citations and inserting the table are on the References tab, in the Table of Authorities group:

Table of Authorities group on ribbon

You click Mark Citation to bring up a dialog box that you use to mark cites. Then, when you’re ready to insert the TOA, click Insert Table of Authorities.

Word’s user interface could be much better. The Mark Citation dialog box is not initially easy to understand:

Mark Citation dialog

Explanation of the dialog box

Here is what each element of the dialog box is for. What you’re doing is creating a list of authorities that is stored in the document, each with a long (full) form, a short form, and a category:

Mark Citation dialog annotated

1. Selected text: You select a cite in the document and this  box initially displays the text you have selected. You edit the text in this box (which doesn’t change the document text) to create the full form of the TOA entry (how you want it to appear in the TOA) the first time you mark a particular authority. For instance, you insert a line break after the case name and delete the pin cite, as shown here.

2. Category: Assign a category to the authority.

3. Short citation: Like the Selected text box, this box initially displays the text you have selected. You edit this text to create the short form of the authority (used for your own reference for future cites, i.e., the short form that is used in the brief).

As you add authorities, each short citation is added to the list box (4.) below this text box. Later, when you want to mark a subsequent cite to an authority that you have already marked, you select the cite in the brief, then select the short citation from this list box and click Mark. (There’s a shortcut for this, which I discuss below.)

5. Long citation: This box displays the long citation that corresponds to a short citation that you have selected in the list of short citations, which can be helpful in refreshing your memory about a cite or checking for other issues.

Note, since the dialog box isn’t resizable, the Long citation box won’t display all of a lengthy citation.

6. Next Citation: Don’t use this. It doesn’t work (it uses pattern matching to find things that look like cites, but it is no substitute for reading).

7. Mark: Click this when you have finished the text box edits (for an initial cite) or selected the short citation (for a subsequent cite), and are ready to mark the cite.

8. Mark All: Will mark all instances of text matching the short citation. It’s doubtful you’d want to do this. It apparently just looks for the exact word(s) you chose as the short citation.

9. Category: Displays a list of available categories and allows you to customize categories.

Now, most people are probably unlikely to understand all of that at the first glance of this little dialog box. And Microsoft’s help doesn’t go into this detail.

But once you understand what you’re doing, and have some basic keyboard and mouse skills (discussed below), you’ll fly through a TOA job.

Tips for using Word’s TOA tool

Here are a few tips you can follow to make the use of the Word tool easier:

1. Keep the dialog box open.

You don’t need to close the Mark Citation dialog after you mark a cite. Keep it open next to your document window (don’t maximize the Word window if you’re using only one monitor). The dialog box will refresh when you click on it. Scroll through your document, select your cites, then work with the dialog box.

2. Use good basic keyboarding techniques.

The line break after the case name is Shift+Enter (in Windows).

Learn how to move around and select text: use combinations of the shift, control, arrow, home and end keys (combinations that are fairly universal in Windows programs) to move and select text quickly in various ways, e.g., to delete all the text after the short citation.

The arrow up and down keys are also convenient for scrolling through the list of short citations.

3. Shortcut for subsequent cites

When marking a subsequent citation to an authority already in your list, if the text you have selected matches exactly a short cite in the short cite list (ok to have spaces on either side), you can go straight from selecting the text to clicking Mark—no need to locate it in the list. (If you click the dialog box to refresh it, you should see that the short cite is already selected in the list, and the category is grayed out.)

Fixing mistakes

Some easy mistakes to make are: assigning the wrong category; not formatting the long citation completely; not editing the short citation completely. These can all be fixed easily by editing the field codes that the TOA tool generates.

Understanding Word’s field codes

Word marks a cite by inserting a “field code” (or “field”) into the document text. The field code’s font is formatted as “hidden,” so you need to make sure you are viewing hidden characters by toggling the Show/Hide button on:

Show/Hide button

Word calls the fields used to mark cites “TA” fields. (The “TOA” field is the TOA table.) Here are a TA field for an initial cite:

Field code for initial cite

and one for a subsequent cite:

Field code for subsequent cite

I’ll explain the elements of the initial cite field:

Field code for initial cite annotated

1. The long form of the citation (as you edited it in the Selected Text box). This is preceded by an “\l” switch.

Switches are codes for settings that control the field code’s behavior. They are preceded by a backslash.

2. The short form of the citation, preceded by an “\s” switch.

3. The category (as a numeral), preceded by a “\c” switch.

You can edit any of these items simply by typing inside the field code. For example, if you forgot to insert a line break after the case name, insert it here.

If you assigned the wrong category, just change the “\c” number to the correct one. The numbers correspond to the position of each category in the Categories dropdown in the dialog box (or you can examine another field code to find the correct number).

The changes you make to the initial cite field code will be reflected in the dialog box the next time you click on it to refresh it.

If you want to edit the short citation, there is an additional complication if you marked any subsequent cites using the short form you now want to change. You’ll need to find those other cites and edit them or re-mark them. They won’t change automatically.

Also, since these fields contain a short citation form that now does not correspond to any authority’s full form, if you find one in the list of short citations, the Long Citation text box will show “Authority not available” and the cite will not be included in the table. In fact, this is a good quality check: scroll through the list of short citations and make sure each is associated with a correct long citation.

Custom categories

If you want to use categories that aren’t in your built-in category list, it certainly can be done, but you need to be aware of a complication if you intend to share your document with another user (e.g., your staff or a colleague).

Custom categories created through the Mark Citation dialog are saved in your user profile, so they are user-level settings, not document-level. They are not saved with the document, and will not travel with the document to another user. There is a workaround, however, for making a custom category TOA shareable, and you may consider it to be a best practice for any custom category TOA.

Let’s use the example that you want to separate state cases from federal cases, and want to have a custom category for each. We’ll look at the non-sharing and sharing scenarios.

Scenario 1: You are the only user

If you do not intend to have another user work with the Word document, creating custom categories through the Mark Citation dialog is pretty straightforward. Click the Category button, which launches a separate Edit Category dialog:

Edit Category dialog

In the Category list, go down to where the list changes from named categories to numbers. (It’s better to use the numbered, unnamed categories than to overwrite and lose an already-named category.) Select one of the numbers, type the new category name in the Replace with box and click the Replace button (you need to click Replace, not just OK). Repeat this for any more custom categories you want, then click OK to close this dialog.

Let’s say you replaced “8” with “Federal Cases.” Now, using the Mark Citation dialog, you’ll see “Federal Cases” in the 8th position of the dropdown, and your field codes for federal cases will indicate “\c 8″. When you generate your TOA, Word will include the heading “Federal Cases” for this category.

Your custom categories will remain available for other documents in Word.

Scenario 2: You need to share the document with other editors

Since custom categories are not a document-level setting, other editors of your document will not see them when marking cites, and when they update the TOA, the heading “Federal Cases” in Scenario 1 will revert to “8.” But there is a fairly simple workaround. The strategy is to use the numbered categories, as in Scenario 1; however, you’ll prevent Word from generating the heading, and instead you’ll type the heading manually.

First, mark your cites using the numbered categories. (You can rename the categories as in Scenario 1, to help yourself remember which number goes with which custom category, but it’s not necessary.) Then, generate your TOA. The heading, whether it’s “Federal Cases” or “8,” will be generated.

The workaround at this point requires making a simple edit in the TOA field code (not the TA field shown above, but the actual table). First, understand that each category of your TOA is generated as a separate TOA field code. (That’s why, for instance, when you right-click on the Cases section and update the field, Statutes and other categories don’t update.) The field starts at the heading and goes to the last entry in the list of authorities for that category.

Note: You should have Show/Hide toggled to Hide when updating a TOA or TOC, to ensure the page numbers are correct.

What you’ll do is edit the custom category field by taking out the switch that tells Word to automatically generate the heading. At the top of the field (before the “8” heading), hit enter once or twice to give yourself space for the new heading. Right-click the category field, and select “Toggle Field Codes”:

TOA toggle field code

You’ll see the field code with its switches:

TOA field code with switches

The “\h” switch, included by default, is responsible for the heading (the name of the category) being generated. You simply delete this switch from the code:

TOA field code without h switch

Right-click and update the field, and you’ll see the list of authorities, but no heading. Simply type your own heading for the custom category.

I hope this quick primer answered some questions and helped allay any qualms you might have about running your own TOAs.

Kenneth Hester is a Microsoft Office Specialist Master (2013, 2010, 2007, 2003) and a Microsoft Certified Application Developer.

Numbering in Word – Think About Document Structure

In Part 1, I outlined a few of the challenges with automatic numbering in Word that trip up traditional document support users. These examples included:

  • Over-reliance on and conflation with paragraph styles
  • Handling multiple, independent lists
  • Handling separate outlines in exhibits or schedules

I’d like to step back now and observe the more general problem that underlies all of these failures. The problem is not thinking about the document structure. People are so focused on getting a number that looks right, they’re not seeing the big picture, which is the document itself, not the numbering.

Word supports numbering in many ways, with many options. The people who developed Word weren’t trying to overwhelm or confuse future users, they were trying to support the many ways documents are structured.

Agreement numbering

Let’s take an example – an agreement. Typically, an agreement is numbered in an outline form, such as:


1.1 Representations of the Seller. The Seller represents that:

(a) blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.

(b) blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.

Typically, legal documents like this will use Word’s heading styles (which are paragraph styles1) to apply the outline numbering. “Article I” is Heading 1, “1.1” is Heading 2, “(a)” is Heading 3, etc.

1 Heading styles are actually linked styles, not just paragraph styles, but they must be used as paragraph styles to get numbers.

That’s pretty standard and simple. So, anybody see a problem with it?

Well, the (a) and (b) paragraphs aren’t headings, are they? We’re calling them “Heading 3″? And only part of the 1.1 paragraph is a heading.

So, even at this elementary level, we’re already ignoring document structure – calling the paragraphs something they’re not – in the quest to get a number in front of them.

Well, Ken, are you suggesting that the profession abandon using heading styles for agreements?

No, it’s too ingrained and convenient. It’s a convention. But I’m saying you should think about what you’re doing in terms of document structure. Users have been trained to work with these imperfections, and have done it for so long, that they don’t think about it. And that’s what leads to problems.

Let’s say further down this agreement there’s something like this:

7.2 Something. Seller will do something under these conditions:

a) something;
b) something;
c) something.

Except that if

1) something;
2) something;
3) something,

Uh oh! The heading styles don’t use “a)” or “1)” formats at that level! What to do? A lot of users are so knee-jerked into heading styles, they’ll modify the heading outline to make some of the heading style levels use these formats with this indent level. And, to avoid messing up the work they’ve done previously in the document, which probably uses several heading levels, they’ll assign it to a lower, so far unused level, like 7 or 8. And they end up with an outline that looks like this:

Is that ridiculous? Yes, that is ridiculous. For one thing, that is saying that those items are at the 7th and 8th level of the outline, which, clearly, they’re not. And if you happen to get to the actual level 7 in your main outline, then you’ve got a conflict. Not to mention that skipping levels (from 2 to 7) flies in the face of the concept of outlining.

The better way to approach this problem is to think about the document structure. The “a), b) c), except 1), 2) 3)” part doesn’t fit with the “ARTICLE I, 1.1, (a), (i)” numbering, and it isn’t serving the same purpose as those main paragraphs. It’s just a list of things within a main section and it happens to be numbered. It’s not part of the main (heading styles) outline, so don’t try to shoehorn it into that outline.

Word allows you to have any number of numbered lists in a document. The main heading outline is only one list. If this particular kind of list is infrequently used in the document, you can just use the numbering buttons to apply the numbering. This creates a standalone list.2 Or, if it recurs, you can create a list style (which I discussed in Part 1).

2 There are some technical issues with using the numbering buttons, which I will address in a future post.

The “a), b) c), except 1), 2) 3)” idiom is fairly common, and users complain that it’s “inconsistent numbering,” which gives them a hard time. Well, it’s not inconsistent numbering. It’s separate numbered lists (separate from the main document outline). Separate lists give users a hard time, if they don’t think about document structure enough to recognize a separate list.

Offering memoranda

I return to the example from Part 1 of the Offering Memorandum. The Description of [Securities] sections in these documents feature lots of independent lists. (I’ll call it description of notes or DoN.) For example:


This covenant will not prohibit the Incurrence of…

(1) Indebtedness Incurred by…

(2) the incurrence of intercompany…

(a) if the Issuer is the lender…

(b) if the Issuer or a Guarantor is…

For purposes of determining…

(1) in the event…

(2) all Indebtedness…

The first “(1), (2)” list is separate from the second one. If you’re not thinking about document structure, you might not recognize or care that they’re separate lists. If you’re only thinking about the numbering, and are (as is typical) over-relying on paragraph styles for numbering, you end up groping for unused heading styles, or “List Number” type paragraph styles, and/or restarting the numbering over and over. Plus, if the lists vary in numbering format, you might run out of styles.

Or you may try to use something like “definition” styles. In a typical definition style numbering scheme, the first level of the numbering outline is actually not numbered. The purpose of this is to support the typical list of definitions, where the definition paragraphs are not numbered, but they may be followed by “(a), (b), (c)” type lists. The reason the non-numbered paragraphs are included in the numbering outline is to use the option to “restart” the numbering of Level 2 paragraphs after each Level 1 paragraph.

It looks like this:

This is a useful, though somewhat problematic, solution for definitions sections. One problem with it is that it makes navigating the paragraphs with the keyboard more difficult (because Word treats each definition paragraph as numbered, even though there’s no number—as you navigate from paragraph to paragraph with the control and arrow keys, you get an unwanted extra stop on each definition paragraph).

Using this kind of numbering for a description of notes section can work, but if you actually use the styles called “Definition,” you’re calling things that aren’t definitions “definitions.” Again, ignoring the document structure.

A better idea may be to create an outline similar to definitions outlines, but use style names more semantically appropriate for a description of notes. But it’s not quite the same as a definitions section because the paragraphs in a DoN don’t serve as unique a purpose as definition paragraphs. They’re really just body text, some of which happen to set off lists. So you’ll have paragraphs that are serving the same purpose called different styles. You’re inventing a style, or class, of paragraph that is defined only by the fact that it sets off a list.

Moreover, the many DoN lists are often inconsistently formatted, and may differ from the definition numbering.

My suggestion for DoNs, as discussed in Part 1, is to use list styles, not paragraph styles. List styles are only concerned with numbering, so you won’t be changing the paragraph styles to something that clashes with the document structure.


A schedule or exhibit is clearly separate from the main document in terms of structure. So, again, you don’t want to use a list from the main document. It’s a separate outline. Use a separate outline in Word.


Numbering, really, is not structure. It’s just enumerating things. The things are part of a logical structure, and the way they’re numbered should follow that structure.

If it’s the main document outline, use the main outline numbering. A separate outline, a different numbered outline. A one-off list? Simple direct numbering. Numerous similar independent lists? Separate lists using a list style.

Kenneth Hester is a Microsoft Office Specialist Master (2013, 2010, 2007, 2003) and a Microsoft Certified Application Developer.

Word – Watch Out for Hidden Headers and Footers

Here’s a simple question: You open a one-page Word document. How many headers and footers does it have?

The answer, surprisingly, is three headers and three footers.1 It’s always three. And you very well might not be able to see the content in all of them.

There is 1) the “primary” header and footer, 2) the “first page” header and footer, and 3) the “even pages” header and footer. The primary footer is the default for every page in the section. (I’ll discuss headers and footers interchangeably; the same points apply to both.) The “first page” is a different footer, optionally shown for the first page in the section (often used in legal documents). The even pages footer, similarly, is optionally shown for the even-numbered pages (used for book-type publications).

Note I said optionally shown, not optionally included, because you can’t delete them. (You can delete their contents, of course.)

Every section in every Word document has all three headers and footers. This is important to understand. When you uncheck these two boxes:

…you’re not deleting anything. You’re only hiding those different headers/footers (i.e., from the printout and print layout view), and they can be un-hidden later.

This issue came to light recently when working with a client who had based a document on a form, and needed to remove the form’s artifacts. The document looked fine on his computer, but when he opened it on a tablet… what the? … There was the form header, right on the front page.

Apparently, the tablet app didn’t use the same logic as the PC app as far as displaying headers, and it was showing the first page header, which had been unchecked and thus hidden … on the PC. Yikes.

Another pitfall scenario: A section with “Different First Page” checked that has only one page. There, you can’t see the primary footer.

What to do to avoid such problems? Obviously, the best practice is to start with a good, trusted template. If you must use an unknown template, a good metadata tool should check for hidden headers/footers. Or your modern legal support professional could write some simple code to inspect all header and footer content.

You could check them all manually by adding page breaks to every section if needed, so that there are at least three pages in each, then going through the headers and footers and checking both boxes for each section (obviously easier if you delete all the content so you start with only one section).

You can also use Find and Replace if you’re looking for something specific. Word will find the content in the hidden headers/footers. But of course, it won’t find something you don’t know to look for.

1 This is demonstrable in the VBE (Visual Basic Editor). Execute:

print selection.sections(1).footers.count

It’ll always be three.

Kenneth Hester is a Microsoft Office Specialist Master (2013, 2010, 2007, 2003) and a Microsoft Certified Application Developer.

Deleting a Section Break in Word (and Preserving Your Formatting)

Have you had the delightful experience of deleting an unwanted section break in a Word document, and then seeing your formatting go to pieces?

This unexpected result is due to a counterintuitive relationship between sections and section breaks. Essentially, the section break relates to the section above it, not the section below it. (See, e.g., this Microsoft support article.) So, when you delete the break, you’re removing the formatting of the section above (which is what you probably want to keep), and retaining the formatting of the section below instead.

The solution for retaining the formatting of the section above is, therefore, to format the section below to be identical to the section above. That sounds easy, but unfortunately, a lot goes into section formatting—page size and orientation, margins, headers and footers, page borders, etc. So, if you look online for how to accomplish this, you find disappointing solutions involving many steps.

The easy way to do it is to run some code that does all the work for you. My code below will make it quick and painless. What it does is assign the pertinent properties of the section above to the section below, plus it copies the headers and footers and even the page borders to the section below. So, when you then delete your section break, you keep your current section’s formatting.

Note: If you don’t have experience running custom code in Word, there are plenty of easy guides out there, e.g., this one. Or I may write a new post on that.

So, install the macro code below (copy it to your Normal or some other template). Put your cursor in the section above the break, and run the “PrepareToDeleteSectionBreak” macro. You’ll see your next section assume the correct formatting. You can then safely delete the section break.

Modern Legal Support provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. Always back up your documents before running any code.

' Code by Kenneth A. Hester

' PrepareToDeleteSectionBreak()
' Sets the following section's
' (and section's child objects') properties
' equal to the current section's,
' so that the break can be deleted
' without losing the current section's
' formatting.

Public Sub PrepareToDeleteSectionBreak()
    Dim s1 As Section
    Dim s2 As Section
    Set s1 = Selection.Sections(1)
    Set s2 = ActiveDocument.Sections(s1.Index + 1)
    DuplicatePageSetupProperties s1, s2
    DuplicateColumnProperties s1, s2
    DuplicateBorderProperties s1, s2
    DuplicateHeadersAndFooters s1, s2
    DuplicatePageNumbers s1, s2
    Set s1 = Nothing
    Set s2 = Nothing
    MsgBox "You may now delete the section break.", vbOKOnly, "Delete Section Break ||"
End Sub

Private Sub DuplicatePageSetupProperties(s1 As Section, s2 As Section)
    With s2.PageSetup
        ' first set up the size properties (some other properties depend on these)
        .Orientation = s1.PageSetup.Orientation
        .PageHeight = s1.PageSetup.PageHeight
        .PageWidth = s1.PageSetup.PageWidth
        .TopMargin = s1.PageSetup.TopMargin
        .BottomMargin = s1.PageSetup.BottomMargin
        .LeftMargin = s1.PageSetup.LeftMargin
        .RightMargin = s1.PageSetup.RightMargin
        .FooterDistance = s1.PageSetup.FooterDistance
        .HeaderDistance = s1.PageSetup.HeaderDistance
        .MirrorMargins = s1.PageSetup.MirrorMargins
        .VerticalAlignment = s1.PageSetup.VerticalAlignment
        .Gutter = s1.PageSetup.Gutter
        .GutterPos = s1.PageSetup.GutterPos
        .GutterStyle = s1.PageSetup.GutterStyle
        .FirstPageTray = s1.PageSetup.FirstPageTray
        .OtherPagesTray = s1.PageSetup.OtherPagesTray
        .LineNumbering = s1.PageSetup.LineNumbering
        .SectionDirection = s1.PageSetup.SectionDirection
        .SuppressEndnotes = s1.PageSetup.SuppressEndnotes
        .TwoPagesOnOne = s1.PageSetup.TwoPagesOnOne
        .DifferentFirstPageHeaderFooter = s1.PageSetup.DifferentFirstPageHeaderFooter
        .OddAndEvenPagesHeaderFooter = s1.PageSetup.OddAndEvenPagesHeaderFooter
        .SectionStart = s1.PageSetup.SectionStart
    End With
End Sub

Private Sub DuplicateColumnProperties(s1 As Section, s2 As Section)
    Dim i As Long
    With s2.PageSetup.TextColumns
        .SetCount s1.PageSetup.TextColumns.Count
        .EvenlySpaced = s1.PageSetup.TextColumns.EvenlySpaced
        .FlowDirection = s1.PageSetup.TextColumns.FlowDirection
        .LineBetween = s1.PageSetup.TextColumns.LineBetween
        If s1.PageSetup.TextColumns.Count > 1 Then
            For i = 1 To .Count
                .Item(i).Width = s1.PageSetup.TextColumns(i).Width
                If i < .Count Then
                    .Item(i).SpaceAfter = s1.PageSetup.TextColumns(i).SpaceAfter
                End If
            Next i
        End If
    End With
End Sub

Private Sub DuplicateBorderProperties(s1 As Section, s2 As Section)
    Dim i As Long
    For i = 1 To s2.Borders.Count
        With s2.Borders(i)
            .LineStyle = s1.Borders(i).LineStyle
            If .LineStyle <> wdLineStyleNone Then
                .LineWidth = s1.Borders(i).LineWidth
                .ArtStyle = s1.Borders(i).ArtStyle
                .ArtWidth = s1.Borders(i).ArtWidth
                .Color = s1.Borders(i).Color
                .Visible = s1.Borders(i).Visible
            End If
        End With
    Next i
    With s2.Borders
        .AlwaysInFront = s1.Borders.AlwaysInFront
        .DistanceFrom = s1.Borders.DistanceFrom
        .DistanceFromBottom = s1.Borders.DistanceFromBottom
        .DistanceFromLeft = s1.Borders.DistanceFromLeft
        .DistanceFromRight = s1.Borders.DistanceFromRight
        .DistanceFromTop = s1.Borders.DistanceFromTop
        '.Enable = s1.Borders.Enable ' Don't use - sets the line style to the default line style and sets the line width to the default line width. (See MSDN)
            ' Also see - setting applies to all sections
        .EnableFirstPageInSection = s1.Borders.EnableFirstPageInSection
        .EnableOtherPagesInSection = s1.Borders.EnableOtherPagesInSection
        '.JoinBorders = s1.Borders.JoinBorders ' apparent bug: removes borders from other sections
        '.SurroundFooter = s1.Borders.SurroundFooter ' apparent bug: removes borders from other sections
        '.SurroundHeader = s1.Borders.SurroundHeader  ' apparent bug: removes borders from other sections
    End With
End Sub

Private Sub DuplicateHeadersAndFooters(s1 As Section, s2 As Section)
    ' first link to previous (to copy them), then duplicate setting
    Dim i As Long
    For i = 1 To 3
        s2.Headers(i).LinkToPrevious = True
        s2.Headers(i).LinkToPrevious = s1.Headers(i).LinkToPrevious
        s2.Footers(i).LinkToPrevious = True
        s2.Footers(i).LinkToPrevious = s1.Footers(i).LinkToPrevious
    Next i
End Sub

Private Sub DuplicatePageNumbers(s1 As Section, s2 As Section)
    ' PageNumbers behaves like a property of the Section object, not a HeaderFooter object.
    ' If you change one property for one HeaderFooter.PageNumbers,
    ' it changes the same property for all other HeaderFooters.
    ' Therefore, only need to apply to one HeaderFooter object
    With s2.Footers(1).PageNumbers ' 1 is primary
        .NumberStyle = s1.Footers(1).PageNumbers.NumberStyle
        .RestartNumberingAtSection = s1.Footers(1).PageNumbers.RestartNumberingAtSection
        If .RestartNumberingAtSection Then
            .StartingNumber = s1.Footers(1).PageNumbers.StartingNumber
        End If
        If s1.Footers(1).PageNumbers.IncludeChapterNumber Then
            .IncludeChapterNumber = True
            .HeadingLevelForChapter = s1.Footers(1).PageNumbers.HeadingLevelForChapter
            .ChapterPageSeparator = s1.Footers(1).PageNumbers.ChapterPageSeparator
            .HeadingLevelForChapter = 0
            .IncludeChapterNumber = False
        End If
        .DoubleQuote = s1.Footers(1).PageNumbers.DoubleQuote
    End With
End Sub

Note, this code is not just a line-for-line enumeration of all the section properties. I’ve deliberately left some out and commented out others. This is because it won’t work if you apply some of these, or apply them in the wrong order. Also, as noted in comments, there are some buggy behaviors in Word VBA that I’ve had to discover and work around. Also, of course, this won’t work on a protected document.

Thinking of sections brings to mind some other issues. Stay tuned for a post on headers and footers that will include an important security issue, and an executive summary of how headers and footers work in Word. [Edit: Here is that post.]

Kenneth Hester is a Microsoft Office Specialist Master (2013, 2010, 2007, 2003) and a Microsoft Certified Application Developer.