Adding line numbers to a document?

I

Ian

Using Word 97.

I am preparing a large document that needs to include a line number on
every fifth line, restarting at the top of each page. Something like
this:

~~~~~~~~~~~~~~
first line of text
second line of text
third line of text
fourth line of text
5 fifth line of text
sixth line of text
seventh line of text
eighth line of text
ninth line of text
10 tenth line of text
eleventh line of text

~~~~~~~~~~~~~~

etc, down to the bottom of the page. Then start this numbering again on
the next page.

How do I accomplish this?
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Ian,

From the File menu, select Page Setup and then go to the Layout Tab and
click on the Line Numbers button at the bottom of the dialog. The Line
Numbers dialog will then open and you can select the choices that you
require in that dialog.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
P

Peter Hewett

Hi Ian

You can accommplish this but you need to understand that Word is not really
line oriented. Word has no internal entity called Line or Page! The reason
I'm warning you about this up front is that the same document using
different printer drivers can produce slightly different results. In other
words you can get inconsistent results from system to system.

Also, I'm not sure of whether your document contains tables, trextboxes,
frames etc. The code gets a lot more complex if you have to deal with these
entities. Adding a line number at the start of certain lines may also cause
that line to wrap to the next line.

Here's some simple code that can cope with a simple straightforward text
document:

Public Sub LabelEvery5thLine()
Dim lngLines As Long
Dim lngLastPage As Long
Dim lngThisPage As Long

' Start at the beginning, we have to use the Selection object
' as the Range object does not support Move(wdLine)
Selection.HomeKey Unit:=wdStory
Do
If Selection.Move(wdLine) = 0 Then
Exit Do
Else
lngThisPage = Selection.Information(wdActiveEndPageNumber)
If lngThisPage = lngLastPage Then

' Only number every 5th line
lngLines = lngLines + 1
If (lngLines Mod 5) = 0 Then

' Add number to line
Selection.InsertBefore CStr(lngLines)
End If
Else
' Reset for a new page
lngLastPage = lngThisPage
lngLines = 1
End If
End If
Loop
End Sub


HTH + Cheers - Peter
 
P

Peter Hewett

Hi Doug

In all the years I've been using Word I've never tried that option!

LOL!!! You can learn something new every day!

Cheers - Peter
 
I

Ian

Well, knock me down with a feather! I knew about that option for
numbering *every* line, but didn't realize you can number in increments
as well. It doesn't work exactly as expected when it encounters pictures
or tables, but that isn't a problem -- the line numbers are only
required for cross-referencing, and it doesn't matter if they are not
exactly right.

And I'm real disappointed now -- I was looking forward to getting into
some deep VBA!

Many thanks Doug.

--
Ian



In message <[email protected]>, Doug Robbins - Word
MVP - DELETE UPPERCASE CHARACTERS FROM EMAIL ADDRESS
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Peter,

Especially in these newsgroups!

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top