Ditto. Although, this is not intuitively easy. Give it a try and post what you come up with.
Just to be clear about what you wish to do:
1.1 Lsdalhdaldhaldha
1.1.1 Aldhaldhald
Adas;dj;ajdad;jad
1.2 Ajdlajd;ajd;adja;dja
Some text here
1.2.1 Yadda blah
Sghdkshdlsdj [highlight]text[/highlight] here
You want to be able - if you highlight/select the text "text" - to put "1.2.1 Yadda blah" into a string variable.
Yes?
Some hints:
1.2.1 is .Range.ListFormat.ListString
Yadda blah is .Range.Text
Two different things, and they are both properties of the paragraph:
1.2.1 Yadda blah
NOT, repeat NOT, the paragraph:
Sghdkshdlsdj [highlight]text[/highlight] here
Which is the paragraph you are using. So...you have to work backwards, finding the paragraph that is using a heading style BEFORE the paragraph that has the text you are testing. If the paragraph you are testing is not right after that heading style paragraph, say:
1.2 Ajdlajd;ajd;adja;dja
Some text here
1.2.1 Yadda blah
This is a first paragraph.
This is a SECOND PARAGRAPH.
And a third, where you are [highlight]testing[/highlight]
Then you have to iterate back, and back, until you DO get a paragraph with a ListString.
The coding itself is not horribly difficult, it is just understanding the object model. I just did it now, with three variables:
Dim r2 As Range (to be able to use the range of paragraphs)
Dim j As Long (a counter, moving backwards through paragraphs, if required)
Dim Yeah As Boolean (a boolean to set if testing paragraph range DOES have a ListString)
and 9 (nine) lines of code.
Gerry