Words Collection

The Words collection is read-only and represents all the words in the specified document, range or selection.


This is the Words collection for the current selection

ActiveWindow.Selection.Words 

This is the first word in the current selection

ActiveWindow.Selection.Words(1) 

Each item in the Words collection is a Range object. There is no Word object.
Every item in the words collection includes the word and the space after the word.


You can remove the space by using the RTrim() function.


Words(index) - where index is the position of the word in the collection.


If the Selection is the insertion point and it is immediately followed by a space then this line refers to the word BEFORE the selection.

ActiveWindow.Selection.Words(1) 

If the Selection is the insertion point and it is immediately followed by a character then this line refers to the word AFTER the selection.

ActiveWindow.Selection.Words(1) 


Count Property

The count property returns the total number of words and also includes punctuation and paragraph marks.

ActiveWindow.Selection.Words.Count 

Counting Words Only

If you want to obtain just the total number of words in a range or selection you can use the Word Count dialog box.

Set dlgWordCount = Dialogs(wdWordDialog.wdDialogToolsWordCount) 
dlgWordCount.Execute
iTotalWords = dlgWordCount.Words


Sentences Collection



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext