PDA

View Full Version : Heading / Section number



BoatwrenchV8
09-06-2012, 02:02 PM
Hello again,

I need the heading number where the cursor is located. In the following example, "THE CURSOR IS HERE!!" is where the cursor is located and is in section 1.1.2. What code would give me the section number of 1.1.2?
This piece of information is needed for a different macro I am working on.


1. First Heading

1.1 This

1.1.1 Blah Blah

1.1.2 THE CURSOR IS HERE!!

1.2 That

1.3 Other Thing

Frosty
09-06-2012, 07:04 PM
I think you're looking for the .ListString property... check it out in help. But you're confusing me with your use of Heading/Section. Let me know if you need more to go on...

fumei
09-07-2012, 02:25 PM
Boat, 1.1.2 (example) is a heading. While you, as an author, may think of this and indeed organize things, as a "section', it is NOT a section as Word understands sections. unless of course you have inserted a section break between ALL of the numeric lisings.

I think Frosty is correct, you want the ListString.

BoatwrenchV8
09-07-2012, 05:08 PM
Frosty and Fumei,
Sorry for the confusion as you are correct, I am saying section but as far as Word is concerned, it is a Heading. In the example blurb I gave, I need the value 1.1.2 from the Heading 3 style when the insertion point is located there.

Below is the code I have tried in the immediate window of a sample document. What am I missing?

msgbox activedocument.Range.ListFormat.ListValue
msgbox activedocument.Range.ListFormat.liststring
msgbox activedocument.Sections(1).Range.ListFormat.ListString
msgbox activedocument.Sections(1).Range.ListFormat.ListValue

fumei
09-07-2012, 08:55 PM
What you are missing is that none of those have anything to do with Headings. The first two, you are trying to get a value for the entire document.

The second two, you are trying to get a value for the entire Section 1.

Try doing some reading up on Range as it applies to parts of a Word document. Yes, Range shows ListFormat property...but it only applies to the range of a paragraph. The Range of a table cell does not have a ListFormat...although the range of PARAGRAPH in the cell does.



1.1.1 some text blah

The above PARAGRAPH has a heading level, and ListString.

Note that:

1.1.1 some text blah

Some text in this "section" yadda yadda.

1.1.2 some other text blah

The numeric starting paragraphs have a ListString (assuming it is a heading!), the text in between does NOT.

So....if you put the cursor in the paragraph starting 1.1.2 and execute:
MsgBox Selection.Paragraphs(1).Range.ListFormat.ListStringreturns 1.1.2

I believe this answers your: 1.1.2 THE CURSOR IS HERE!!

Frosty
09-08-2012, 06:38 AM
Quick comment: love that you're using the immediate window.
You don't have to use msgbox, though. Just put a ? At the front of the statement instead.
?8 * 8
That will show the result in the window itself.

BoatwrenchV8
10-16-2012, 07:45 AM
Thank you all for your help with this.