Determine full paragraph number string

T

Trevor

Hello all
Is it at all possible to return the full paragraph number
from an outline numbered paragraph. The ListString
property only returns the text of the number of the given
para - I want all it's higher numbers as well. For
example, in:
5. some text
a) more text
i) even more
I want to return "5.a.i" for the "even more" paragraph.
Here's hoping
Trevor
 
H

Helmut Weber

Hi Trevor,
yes, it is.
The following code may need a bit of refinemant.
Is is assumed, that the cursor is in a listparagraph.

Dim s As String ' the accumulated liststring
Dim l As Integer ' the listlevel
Dim p As Integer ' a counter for listparagraphs
Dim r As Range ' a range
Selection.Collapse direction:=wdCollapseStart
Set r = Selection.Range
r.start = 0
r.End = Selection.start
l = Selection.Range.ListFormat.ListLevelNumber
s = Selection.Range.ListFormat.ListString & s
For p = r.ListParagraphs.Count - 1 To 1 Step -1
If r.ListParagraphs(p).Range.ListFormat.ListLevelNumber <
l Then
s = r.ListParagraphs(p).Range.ListFormat.ListString & s
l = r.ListParagraphs(p).Range.ListFormat.ListLevelNumber
End If
Next
MsgBox s
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
K

Klaus Linke

Hi Trevor,

If you need the full context in a cross reference, you could try the \w
switch, or choose "Paragraph number (full context)" in the dialog.
You would get 5.a)i) though, in your example.

In case you need the full context in cross references, it might be
reasonable to change the numbering to
5. some text
a. more text
i. even more
to simplify things.

Regards,
Klaus
 
B

Bruce Brown

Trevor

There is yet another way to do this provided you are using the
built-in Heading styles (it will not work without them):

{ STYLEREF 1 \S }{ STYLEREF 2 \S }{ STYLEREF 3 \S ) = 5.1)i)

This use of the STYLEREF field is undocumented but can come in very
handy.

Selecting the field and pressing Shift-Ctrl converts the field to
text, should you want to do that.

The whole thing could be automated in VBA as well. Hope this gives you
another alternative. - Bruce
 
K

Klaus Linke

Hi Bruce,

Didn't think of that possibility... nice!
It would be useful if you want to reference the current number.

The method should work with any style.
{ STYLEREF 1 } is just a shortcut for { STYLEREF "Heading 1" } ...
(useful if you want to make it independent of the English version).

{ STYLEREF "List Number" \S } ... should work, too.

{ STYLEREF 3 \w } would give you 5.1)i)
With your method, you get the pure number (at least in Word2002, I do),
so
{ STYLEREF 1 \S }.{ STYLEREF 2 \S }.{ STYLEREF 3 \S }.
will get you 5.1.i., even if the styles use 5., 1), and i)

Greetings,
Klaus
 
J

JGM

Bruce Brown said:
Trevor

There is yet another way to do this provided you are using the
built-in Heading styles (it will not work without them):

{ STYLEREF 1 \S }{ STYLEREF 2 \S }{ STYLEREF 3 \S ) = 5.1)i)

This use of the STYLEREF field is undocumented but can come in very
handy.

Selecting the field and pressing Shift-Ctrl converts the field to
text, should you want to do that.

Shouldn't it be SHIFT-CTRL-F9?
Or are you talking about something else?
 
J

JGM

Klaus Linke said:
Hi Bruce,

Didn't think of that possibility... nice!

Very nice indeed!
It would be useful if you want to reference the current number.

The method should work with any style.

It does (and so do all the examples you provided below!), I just tested it
under Word XP.

Cheers!
 
B

Bruce Brown

Oui, Jean-Guy, Shift-Ctrl without F9 was a typo and should have been
Shift-Ctrl-F9.

Klaus, you say "(useful if you want to make it independent of the
English version)." Why would anyone want to do that? (Ha ha ha.)

I almost felt smart for a half second until you came along and showed
all the other STYLEREF examples. It's back to the scarecrow mode for
me while you fly straight to the Wizard with Toto under your arm.
Showoff! - Bruce
 
K

Klaus Linke

Klaus, you say "(useful if you want to make it independent of the
English version)." Why would anyone want to do that? (Ha ha ha.)

Well, we are not in Kansas anymore...

;-) 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