Class LineNumbering (Word VBA)

The class LineNumbering represents line numbers in the left margin or to the left of each newspaper-style column. To use a LineNumbering class variable it first needs to be instantiated, for example


Dim lng as LineNumbering
Set lng = ActiveDocument.PageSetup.LineNumbering

Active

True if line numbering is active for the specified document, section, or sections.


Sub CountByFive() 
 With Selection.Sections(1).PageSetup.LineNumbering 
 .Active = True 
 .CountBy = 5 
 .StartingNumber = 1 
 End With 
End Sub

CountBy

Returns or sets the numeric increment for line numbers.

If the CountBy property is set to 5, every fifth line will display the line number. Line numbers are only displayed in print layout view and print preview. This property has no effect unless the Active property of the LineNumbering object is set to True.


With ActiveDocument.PageSetup.LineNumbering 
 .Active = True 
 .CountBy = 5 
 .RestartMode = wdRestartSection 
End With

DistanceFromText

Returns or sets the distance (in points) between the right edge of line numbers and the left edge of the document text.


With ActiveDocument.PageSetup.LineNumbering 
 .Active = True 
 .CountBy = 5 
 .DistanceFromText = 36 
End With

RestartMode

Returns or sets the way line numbering runs — that is, whether it starts over at the beginning of a new page or section or runs continuously. Possible return values are wdRestartContinuous - Numbers are assigned continuously, wdRestartPage - Numbers are reset for each page, wdRestartSection - Numbers are reset for each section.

You must be in print layout view to see line numbering.


set myDoc = ActiveDocument 
With myDoc.PageSetup.LineNumbering 
 .Active = True 
 .StartingNumber = 1 
 .CountBy = 10 
 .RestartMode = wdRestartSection 
End With

StartingNumber

Returns or sets the starting line number.

You must be in print layout view to see line numbering.


Set myDoc = Documents.Add 
With myDoc.Footnotes 
 .StartingNumber = 10 
 .Add Range:=Selection.Range, Text:="Text for a footnote" 
End With