Using Word Automation to get Heading/Outline Numbers

  • Thread starter Thread starter Charles Law
  • Start date Start date
C

Charles Law

I have a document in the following style

1 Introduction
2 Next Heading
2.1 Sub-section
Some text ...
2.2 Another Sub-section
2.2.1 Getting deeper
3 Another Major Heading
....

My final aim is to iterate through the document in VB.NET, pick out the
headings and text and create a cleaned-up, normalised XML document.

At the moment, I am iterating through the paragraphs in the document, just
picking out the headings. When I look at the text of the heading it does not
include the heading number (which is fair enough). But, how do I retrieve
the heading number? Each heading is formatted with the appropriate heading
style for its level, so "Introduction" is Heading 1, "Getting deeper" id
Heading 3, and so on.

I could look at the outline level and work it for myself, but I presume that
Word knows what number it is going to give to a heading, and it is this
number I would like to get at.

TIA

Charles
 
Hi Mark

Thanks for the reply. I had seen that in fact; I think it was posted in
another thread that I stumbled into.

I have used it as my starting point for creating an xml file, and it helps
me to get things like the style name and page numbers. but unfortunately it
falls short of extracting the outline number of a paragraph.

Charles
 
I suppose another option is to use the table of contents object exposed by word to set up
your XML structure.
 
Yes, a possibility, but I think it is probably maintained independently of
the body of the document, and so could get out of sync. It could also turn
into a sorting exercise, where I traverse the document and attempt to
pigeon-hole each heading as I encounter it.

Charles
 
I have just discovered where it is:

For any paragraph 'p' in the document, the heading number is contained in

p.Range.ListFormat.ListString

I hope someone else will find this useful.

Charles
 

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

Back
Top