Function GETWORDCOUNT()
Dim FD As FileDialog
Dim DocSource As Document
Dim totalWordCount As Long
Dim preWordCount As Long
Dim newWordCount As Long
Set FD = Application.FileDialog(msoFileDialogFolderPicker)
With FD
.Title = "Select the folder that contains the documents."
If .Show = -1 Then
strFolder = .SelectedItems(1) & "\"
Else
MsgBox "You did not select a folder."
Exit Function
End If
End With
strFile = Dir$(strFolder & "*.doc")
totalWordCount = 0
preWordCount = 0
newWordCount = 0
While strFile <> ""
Set DocSource = Documents.Open(strFolder & strFile)
newWordCount = CInt(DocSource.Words.Count)
totalWordCount = newWordCount + preWordCount
preWordCount = totalWordCount
DocSource.Close wdDoNotSaveChanges
strFile = Dir$()
Wend
GETWORDCOUNT = CLng(totalWordCount)
End Function