Working with the Sentences Object

The next rung on Word's text object ladder is the Sentences object. This is a collection of all the sentences in whatever object you specify, be it a Document, Range, or Selection.

As with Words, you refer to specific members of the Sentences collection by an index number, and the resulting object is a Range. For example, the following statement stores the active document's first sentence in the firstSentence variable:

firstSentence = ActiveDocument.Sentences(l)

Again, the Count property can be used to return the total number of sentences in an object. In the following procedure fragment, the Count property is used to determine the last sentence in a document:

With Documents("Remarks.docx")

totalSentences = .Sentences.Count lastSentence = .Sentences(totalSentences) End With

0 0

Post a comment