0
votes

I am creating a Microsoft Word add-in using Visual Studio and C#. The add-in needs to be able to get the "number format text" (not sure if this is the correct terminology) applied by a Multi-level list. For example, a document using the MS Word default Heading styles applied to paragraphs also has a multi-level list applied which automatically numbers the paragraphs with Headings and adds the text "Article " to paragraphs with Heading 1, and applies the text "Section " to paragraphs with Heading 2. The end result is Article 1, Section 1.01, Section 1.02, Section 1.03, Article 2, Section 2.01, etc. The add-in needs to get the "Article 1", or "Section 1.01", etc..

I have tried various properties and methods of Range.Listformat, Range.ListParagrphs, Range.ListStyle, Range.ParagraphStyle, Paragraph.Format, and Paragraph.OutlineLevel but haven't found it yet. Range.ListFormat.ListLevelNumber gives the level as an integer, but not the text and exact paragraph number I am looking for. Does anyone out there know how to get that info? Thanks!

I read these and other but couldn't find what I'm looking for:

how to read multi level list numbers in ms word(word object model)?

Creating a multi-level bullet list with Word.Interop

1
To be able to work with list numbering in Word you need to acquaint yourself with the ListGalleries collection and the WdListGalleryType enumeration. This leads to the ListTemplates collections and for multilevel lists the ListLevels collection. ListTemplates can take an item argument which is a number or name (name is assigned via the .Name) property. For multilevel lists this name is the one that can be assigned in the MultilevelList dialog box. The ListLevel has the linked style property. From the style perspective it is worth investigating the listLevelNumber, ListTemplate properties. –freeflow
Warning: do not try to use the ListGalleries in code as mentioned in a comment. These depend on the display of a particular Gallery in the Word UI. The order (index reference) of the Galleries or even the presence of a particular one can change, depending on user actions or network admin writing to the Registry. Use of this collection is therefore not reliable enough for using in a solution.Cindy Meister

1 Answers

0
votes

To get the literal string for any paragraph's numbered list use

TheParagraph.Range.ListFormat.ListString;