Listing A Function Procedure That Uses Words Word Count Dialog Box to Get the Total Number of Words in the Active Document

Function CountDocumentWords() As Long With Dialogs(wdDialogToolsWordCount) .Execute

CountDocumentWords = .Words End With End Function

Sub DisplayWordCount()

MsgBox "This document contains " & CountDocumentWords & " words." End Sub

This procedure uses Execute to run the Word Count dialog box, and then uses the Words argument to return the number of words in the document. (Note, however, that if you have text selected before running this procedure, it will return the number of words in the selection.)

0 0

Post a comment