Sentences Collection Object

Microsoft Word Visual Basic

Show All

Sentences Collection Object

         
Multiple objects Sentences (Range)
Multiple objects

A collection of Range objects that represent all the sentences in a selection, range, or document. There is no Sentence object.

Using the Sentences Collection

Use the Sentences property to return the Sentences collection. The following example displays the number of sentences selected.

MsgBox Selection.Sentences.Count & " sentences are selected"

Use Sentences(index), where index is the index number, to return a Range object that represents a sentence. The index number represents the position of a sentence in the Sentences collection. The following example formats the first sentence in the active document.

With ActiveDocument.Sentences(1)
    .Bold = True
    .Font.Size = 24
End With

Remarks

The Count property for this collection in a document returns the number of items in the main story only. To count items in other stories use the collection with the Range object.

The Add method isn't available for the Sentences collection. Instead, use the InsertAfter or InsertBefore method to add a sentence to a Range object. The following example inserts a sentence after the first paragraph in the active document.

With ActiveDocument
    MsgBox .Sentences.Count & " sentences"
    .Paragraphs(1).Range.InsertParagraphAfter
    .Paragraphs(2).Range.InsertBefore "The house is blue."
    MsgBox .Sentences.Count & " sentences"
End With