Class Words (Word VBA)

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. To use a Words class variable it first needs to be instantiated, for example


Dim wrds as Words
Set wrds = ActiveDocument.Words

Count

Returns a Long that represents the number of words in the collection.


If Selection.Words.Count >= 1 And _ 
 Selection.Type <> wdSelectionIP Then 
 MsgBox "The selection contains " & Selection.Words.Count _ 
 & " words." 
End If

First

Returns a Range object that represents the first word in a collection of words.


Dim rngFirst As Range
Set rngFirst = ActiveDocument.Words.First

Item

Returns an individual Range object in a collection.

Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position of the individual object.


Dim rngWord As Range
Set rngWord = ActiveDocument.Words(Index:=1)

Last

Returns a Range object that represents the last word in a collection of words.


If Selection.Words.Count >= 2 Then 
 Selection.Words.Last.Bold = True 
End If