Word – MS Word 2013 to 2019 Professional: Numbering paragraphs on the OUTER edge of pages (Marginal Numbers)

microsoft wordnumberingprintingtext formatting

By doing the following:

  • right-clicking the Normal paragraph style,
  • Modify…
  • [Format], Numbering…
  • [Define new number format…]
  • Number style: 1,2,3…; Number format: 1; Alignment: Right

and

  • right-clicking the Normal paragraph style,
  • Modify…
  • [Format], Paragraph…
  • Indentation left: -0.25"; Special: Hanging; by: 0.25"

I managed to create a style which continually numbers paragraphs, looking as follows:

enter image description here

What I want, however, is that the paragraph numbers always appear on the outer edge, i.e., the numbers 12 to 14 should appear on the right edge instead of at the left edge like the previous page.

Like images, tables etc., I must be able to refer to any paragraph number ("as per paragraphs 117 ff."), which is possible with above approach.

Intention: printed report consisting of thousands of paragraphs, to be discussed in great detail, immensely being facilitated by being able to refer to paragraph numbers. And it's simply ugly to have the (possibly partially obscured) numbering to the left on odd numbered pages.

Is such a numbering style even possible?

(Using MS Word 2019 Professional: perhaps we should add a tag for it?)

Best Answer

I saw your question on Stack Overflow, where it was really "too broad" as formulated, but it intrigued me.

It can be done, although not completely automatically, manually and/or with VBA.

  1. Select any (an empty) paragraph and apply a Frame to it. You can find the Insert Frame command in the Developer tab of the ribbon, Controls group, Legacy controls. It's the fourth control from the left

enter image description here

  1. Size the frame, apply the font size you want for the numbers, etc.
  2. Right-click the frame to get to the Format Frame dialog box. For the horizontal position select Outside relative to the Page and fine-tune the distance from the text if necessary. Vertical position should be 0 relative to the paragraph. Make sure "Move with text" and "Lock anchor" are activated. When the dialog box is confirmed the framed paragraph should move to the outside margin of the immediately following paragraph.
  3. Create a new style from this paragraph - it will include the Frame definition.
  4. Test the style by typing in or selecting another empty paragraph and applying the style to it.

The numbering can be generated by placing an SEQ field in each frame, then updating the fields in the document.

At this point, manually, it would be possible to generate the numbering. A long task, of course, for a large document. The following code will cycle all paragraphs in a document, inserting an empty paragraph, an SEQ field and formatting it with the style. At the end, all the fields are updated.

This will, almost certainly (based on the screen shots you show) insert more numbers than you want. You can either go through and delete them manually or alter the code to ignore paragraphs that meet the particular criteria that should not be numbered, or alter the code to skip those paragraphs when generating the frames.

In this code, the style for the frames is named NrPara; if you use a different name you need to change this.

Sub NumberParas()
    Dim doc as Word.Document
    Dim Para As Word.Paragraph
    Dim rngPara As Word.Range, rngParas() As Word.Range
    Dim numParas As Long, counterPara As Long
    Dim numParaStyle As Word.style
    Dim rngNumPara As Word.Range
    Dim sSEQ As String

    sSEQ = "SEQ ParaNum"
    Set doc = ActiveDocument
    numParas = doc.Paragraphs.Count
    ReDim rngParas(numParas - 1)

    'Get an array of the paragraph ranges
    For counterPara = numParas To 1 Step -1
        Set Para = doc.Paragraphs(counterPara)
        Set rngPara = Para.Range
        Set rngParas(counterPara - 1) = rngPara
    Next

    'Insert a paragraph above each existing one, format and insert SEQ field
    For counterPara = LBound(rngParas) To UBound(rngParas)
        Set rngPara = rngParas(counterPara)
        With rngPara
            .InsertBefore vbCr
            .Collapse wdCollapseStart
            .Fields.Add rngPara, wdFieldEmpty, sSEQ, False
            rngPara.style = "NrPara"
        End With
    Next
    doc.Fields.Update
End Sub
Related Question