Line numbering macro for MSWord

L

Legacy 5596

Guest
I would like a simple macro that inserts a superscript sequential number at the beginning of each line of an established body of text (ignoring blank lines obviously). The text size for the number should be 6-8 point so as not to mess up the formatting of the established text (I don't want the inserted number to push the text at the end to the next line).

Example:
1The dog ran after the cat and the cat jumped
2through the window to escape.
3The dog barked furiously but could not follow the
4cat through the small window.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
using MSWords line numbering feature

I have found out MSWord has a built in line numbering feature but that is not useful for what I'm trying to do because the lines are not really part of the text & thus do not carry over in copying & pasting
 
Upvote 0
Work in progress

Saw your post on the excel side ... don't quite have a complete answer for you however maybe this will get the ball rolling:

Sub Macro1()

Selection.WholeStory

Dim nSentences As Integer
nSentences = Selection.Sentences.Count

Dim a As Integer
For a = 1 To nSentences
Selection.Sentences(a).InsertBefore a

Next a

End Sub

It seems to add the numbers but i'm having some difficulty in changing it to subscript.

If i get any further i will let you know.
 
Upvote 0
Work in progress

Ok, i think i have it:

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.WholeStory

Dim nSentences As Integer
nSentences = Selection.Sentences.Count

Dim a As Integer
Dim b As Integer
Dim tempstring As String

For a = 1 To nSentences

Selection.Sentences(a).InsertBefore a
Selection.Sentences(a).Select
tempstring = Str(a)
b = Len(tempstring) - 1
Selection.MoveLeft wdCharacter, 1
Selection.MoveRight Unit:=wdCharacter, Count:=b, Extend:=wdExtend
Selection.Font.Subscript = wdToggle
Selection.WholeStory

Next a

End Sub

Give it a try and let me know...i have not tested it with anything containing more than 30 sentences.
 
Upvote 0
auto line numbering

Wow!!! It worked exactly as I wanted!!! I applied it to a 21 page document.

I did change it to superscript rather than subscript. Now I just need to figure out a few more things:

1. How to make it have an undo all (undo only undoes the last inserted number)
2. How to make a php version to work with the Drupal-based text editor called FCKeditor with a clickable button that applies the line numbers (or removes them -- toggle on-off).

I'm trying to host written theological debates at my website thekingdomcome.com but I noticed from debates I've moderated elsewhere that the biggest need is for documents to be number by sentence so the participants can easily reference the other person's arguments line by line.

So, anyhow, this has greatly helpd. Thanks sooooooo much. You're the greatest.
 
Upvote 0
:)

I'm really glad it worked for you,

Just curious what version of word are you using? I used the undo in 2003 and it erased all the way back to the first line number.

thanks for the challenge, this was my first word macro!
 
Upvote 0
The version I tried it on is 2002 so that might be the problem. But yes, it works real well. Thanks again so much. Fine job.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top