Numbering macro without autonumbering

A

Amy

Hi,

Is there a way to create a macro that numbers each paragraph in a selection
consecutively? I would like the numbers to be inserted right before the
paragraph mark. Also, I don't want to use bookmarks or fields or
autonumbering or a list style. For example, I would like to be able to select
any number of paragraphs in a Word file, and have a macro that numbers each
one, such as:

Paragraph 1
Paragraph 2
Paragraph 3

But only for the selection.

Any advice appreciated.
Thank you
Amy
 
C

Charles Kenyon

There is no such stock macro. You are welcome to write one. You would loop
through the paragraphs in the selection and insert an incrementing number at
the end of each one. This would be hard-coded text, so it would not change.
Note it would be harder to remove or reset these numbers.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
D

Doug Robbins - Word MVP

Use:

Dim i As Long
Dim prange As Range, numrange As Range
Set numrange = Selection.Range
With numrange
For i = 1 To .Paragraphs.Count
Set prange = .Paragraphs(i).Range
prange.End = prange.End - 1
prange.Text = prange.Text & " Paragraph " & i
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Amy

I am also trying to write a macro that numbers paragraphs at the beginning of
each paragraph, and I tried to modify your code but the macro affected things
outside of the selection. Here's what I tried:

Dim i As Long
Dim prange As Range, numrange As Range
Set numrange = Selection.Range
With numrange
For i = 1 To .Paragraphs.Count
Set prange = .Paragraphs(i).Range
prange.Start= prange.StartOf
prange.Text = prange.Text & i
Next i
End With


OR is there a way to do it something like this?

Dim i As Long
Dim rSlc As Range
Dim rTmp As Range
Dim oPrg As Paragraph
Set rSlc = Selection.Range
For Each oPrg In rSlc.Paragraphs
Set rTmp = oPrg.Range
With rTmp
For i = 1 To .Paragraphs.Count
Set oPrg = .Paragraphs(i).Range
oPrg.Range.InsertBefore rTmp.Text & i
Next i
End With


Any advice appreciated,
Amy
 
D

Doug Robbins - Word MVP

Use

Dim i As Long
i = 1
For i = 1 To Selection.Paragraphs.Count
Selection.Paragraphs(i).Range.InsertBefore i & vbTab
Next i

If you want the paragraphs to be formatted with a hanging indent, use

Dim i As Long
i = 1
For i = 1 To Selection.Paragraphs.Count
Selection.Paragraphs(i).Range.InsertBefore i & vbTab
Selection.Paragraphs(i).Format.LeftIndent = InchesToPoints(0.5)
Selection.Paragraphs(i).FirstLineIndent = InchesToPoints(-0.5)
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Amy

Thanks!

Doug Robbins - Word MVP said:
Use

Dim i As Long
i = 1
For i = 1 To Selection.Paragraphs.Count
Selection.Paragraphs(i).Range.InsertBefore i & vbTab
Next i

If you want the paragraphs to be formatted with a hanging indent, use

Dim i As Long
i = 1
For i = 1 To Selection.Paragraphs.Count
Selection.Paragraphs(i).Range.InsertBefore i & vbTab
Selection.Paragraphs(i).Format.LeftIndent = InchesToPoints(0.5)
Selection.Paragraphs(i).FirstLineIndent = InchesToPoints(-0.5)
Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
K

Klaus Linke

There is no such stock macro.

Actually, there are... very old ones, from before the time that
AutoNumbering was introduced:
ToolsBulletsNumbers, ToolsNumberListDefault, and ToolsBulletListDefault.

You can add them to any toolbar (Tools >Customize, Commands tab, Category
"All Commands").

The first lets you choose the numbering scheme, the second and third
continue whatever list you happen to have started.
Say, type
1) First item
Second item
Third item

Select the three paragraphs, then hit the button for ToolsNumberListDefault.

Greetings,
Klaus
 
C

Charles Kenyon

Using these a person can insert a number at the end of the paragraph rather
than the beginning? I've got to look into these.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Charles Kenyon

Thanks for pointing these out. I've switched my toolbar buttons (which I
didn't use) to these commands because they are more stable for quick
application of numbering since they don't rely on list templates. (I still
use custom styles for long-term projects.)
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide




--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
K

Klaus Linke

Charles Kenyon said:
Thanks for pointing these out. I've switched my toolbar buttons (which I
didn't use) to these commands because they are more stable for quick
application of numbering since they don't rely on list templates.

Same here. I don't use AutoNumbering at all any more, and turn it into hard
text when I encounter it.

:-/ Klaus
 
K

Klaus Linke

I don't use AutoNumbering at all any more

.... for lists needing restarts that is. Numbered styles for headings are
fine, though I don't need them that often.

Klaus
 

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