PDA

View Full Version : getting the paragraph heading of current location



yairn
12-15-2015, 08:28 AM
I am trying to create a code that will return what is the paragraph heading number the cursor is currently in.
for example if a I have an outline document with headlines and sub headlines (1, 1.1 ,1.1.1, 2 , 2.1 etc.) and the cursor is currently located inside a paragraph that its heading is 2.2.2 - i would like to create a code that will return the current location heading number (e.g. 2.2.2)

I found the following code. it works well until inside the paragraph contains only "normal" paragraphs. if the section 2.2.2 contains a bullet or numbering list inside it - the macro nwill return a "?" if the cursor is located on or after the bullet list...

how can ignore those bullt lists?

Sub Test400B()

Dim rTmp1 As Range
Set rTmp1 = Selection.Range
While rTmp1.ListParagraphs.count = 0
rTmp1.MoveStart Unit:=wdParagraph, count:=-1
Wend
MsgBox rTmp1.ListParagraphs(1).Range.ListFormat.ListString


End Sub

gmaxey
12-15-2015, 10:12 AM
Something like this:


Sub Test400B()
Dim oRng As Range
Set oRng = Selection.Range
While oRng.ListParagraphs.Count = 0
oRng.MoveStart Unit:=wdParagraph, Count:=-1
oRng.Select
Wend
While oRng.ListParagraphs(1).Range.ListFormat.ListType = 2
oRng.MoveStart Unit:=wdParagraph, Count:=-1
oRng.Select
Wend
MsgBox oRng.ListParagraphs(1).Range.ListFormat.ListString
End Sub

yairn
12-16-2015, 04:03 AM
Something like this:


Sub Test400B()
Dim oRng As Range
Set oRng = Selection.Range
While oRng.ListParagraphs.Count = 0
oRng.MoveStart Unit:=wdParagraph, Count:=-1
oRng.Select
Wend
While oRng.ListParagraphs(1).Range.ListFormat.ListType = 2
oRng.MoveStart Unit:=wdParagraph, Count:=-1
oRng.Select
Wend
MsgBox oRng.ListParagraphs(1).Range.ListFormat.ListString
End Sub

gmaxey
12-16-2015, 07:03 AM
You're welcome. Glad I could help.