Capturing Outline Position

K

Ken Kast

I'm working in Office XP, but need an answer that will work for 2000 and
2003. I have styles Heading 1-4 tied to a customized List. For a particular
paragraph I want to know where in the overall outline it sits. For example,
if after applying the Heading styles I have:
I.
A.
B.
1.
2.
3.
a.
b. I am here

I want to find IB3b, i.e.,
Heading 1: 1
Heading 2: 2
Heading 3: 3
Heading 4: 2

Can this be done in VBA?

Thanks.

Ken
 
S

Stefan Blom

Something like this should work:

Sub main()
Dim MyListFormat As ListFormat
Dim TheListLevel As Long, i As Long
Dim s As String
Set MyListFormat = Selection.Paragraphs(1).Range.ListFormat
If MyListFormat.List Is Nothing Then
MsgBox "No numbered list at the insertion point"
Exit Sub
End If
TheListLevel = MyListFormat.ListLevelNumber
For i = 1 To TheListLevel
s = s & _
MyListFormat.List.Range.ListParagraphs(i). _
Range.ListFormat.ListString
Next i
Debug.Print "List formatting is: " & s
End Sub
 
K

Ken Kast

Thanks, Stefan
Stefan Blom said:
Something like this should work:

Sub main()
Dim MyListFormat As ListFormat
Dim TheListLevel As Long, i As Long
Dim s As String
Set MyListFormat = Selection.Paragraphs(1).Range.ListFormat
If MyListFormat.List Is Nothing Then
MsgBox "No numbered list at the insertion point"
Exit Sub
End If
TheListLevel = MyListFormat.ListLevelNumber
For i = 1 To TheListLevel
s = s & _
MyListFormat.List.Range.ListParagraphs(i). _
Range.ListFormat.ListString
Next i
Debug.Print "List formatting is: " & s
End Sub
 

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