Amar
Amar

Reputation: 1

How to get the paragraph Number from Word Document in VSTO

Suppose we have a paragraph in a document as below:

  1. Orange
  2. Apple
  3. Mango

I need to retrieve the Numbered List for each entities in the paragraph. For Orange- 1, Apple-2 and Mango-3 I have already used the below code to find out the list of Paragraphs in the document. Word.Paragraphs para = ActiveDocument.Paragraphs;

From para object I need to find out the Numbering of the list for each entities.

Upvotes: 0

Views: 607

Answers (1)

Joost Verdaasdonk
Joost Verdaasdonk

Reputation: 327

I'm not 100% I understand your question but it appears you are using a numbered list style on the 3 paragraphs and you would like to get the values of the numbered list style? (1, 2 and 3)

A word Paragraph has in VBA/VSTO/etc.. a Range object On the Range object you will find the ListFormat object which gives you the info you need.

So if you have in your first paragraph: 1. Orange then you can use:

ActiveDocument.Paragraphs[1].Range.ListFormat.ListString

This will give you the "1." And

ActiveDocument.Paragraphs[1].Range.ListFormat.ListValue

This will give you the 1

Good luck

Upvotes: 2

Related Questions