Words Collection Object

Description

A collection of words in a selection, range, or document. Each item in the Words collection is a Range object that represents one word. There is no Word object.

Using the Words Collection

Use the Words property to return the Words object. The following example displays how many words are currently selected.

MsgBox Selection.Words.Count & " words are selected"
Use Words(index), where index is the index number, to return a Range object that represents one word. The index number represents the position of the word in the Words collection. The following example formats the first word in the selection as 24-point italic.

With Selection.Words(1)
    .Italic = True
    .Font.Size = 24
End With
The item in the Words collection includes both the word and the spaces after the word. To remove the trailing spaces, use the RTrim function — for example, RTrim(ActiveDocument.Words(1). The following example selects the first word (and its trailing spaces) in the active document.

ActiveDocument.Words(1).Select
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 Words collection. Instead, use the InsertAfter method or the InsertBefore method to add text to a Range object. The following example inserts text after the first word in the active document.

ActiveDocument.Words(1).InsertAfter "New text "
Properties

Application property, Count property, Creator property, First property, Last property, Parent property.

Methods

Item method.

See Also

Characters collection object, Sentences collection object.