The Paragraph object allows you to work with the paragraphs in a document. The Paragraphs collection contains all of the paragraphs in a document.
Use the Add method to add a new paragraph to the document and to the Paragraphs collection. The paragraph is added before the specified range.
{Add a new paragraph.} paragraph = document.Paragraphs.Add(wordRange);
If a range is not specified, a paragraph is added at the end of the document. |
You can add a new paragraph to the document with the InsertParagraph method. The InsertParagraph method replaces the Range object with the range of the new paragraph.
{Insert a new paragraph.} wordRange.InsertParagraph();
You can also use the InsertParagraphBefore method or the InsertParagraphAfter method to add a new paragraph. The InsertParagraphBefore method inserts the paragraph before the range and expands the Range object to include the range of the new paragraph.
{Insert a paragraph before the specified range.} wordRange.InsertParagraphBefore();
The InsertParagraphAfter method inserts the new paragraph in the document after the range and expands the Range object to include the range of the new paragraph.
{Insert a paragraph after the specified range.} wordRange.InsertParagraphAfter();
You can retrieve a paragraph from the Paragraphs collection with the Item method by the number associated with the paragraph.
{Retrieve the third paragraph from the Paragraphs collection.} paragraph = document.Paragraphs.Item(3);
You can use the First property to retrieve the first paragraph in the Paragraphs collection.
{Retrieve the first paragraph from the Paragraphs collection.} paragraph = document.Paragraphs.First;
You can use the Last property to access the last paragraph in the Paragraphs collection.
{Retrieve the last paragraph from the Paragraphs collection.} paragraph = document.Paragraphs.Last;
The Paragraph object contains several properties to modify the appearance of a paragraph, such as the Alignment property and the Format property.
Alignment property Use the Alignment property to change the horizontal alignment of a paragraph. To specify the alignment, use constants contained in the wdParagraphAlignment enumeration.
{Center the paragraph on the page.} paragraph.Alignment = Word.wdAlignParagraphCenter;
Format property The Format property returns a ParagraphFormat object. The properties from the ParagraphFormat object, such as the Hyphenation property, allow you to format the paragraph.
{Automatically hyphenate the paragraph.} paragraph.Format.Hyphenation = true;