Thursday, December 19, 2013

Function to Find the number of words in a word document

Dim oWord, Doc, currentDocument
Doc = "Give the path of the document"
Set oWord = CreateObject("Word.Application")
oWord.DisplayAlerts = 0
oWord.Documents.Open Doc
Set currentDocument = oWord.Documents(1)
Dim nWords, n
nWords = currentDocument.Words.count
Print "Number of Words: " & nWords
For n = 1 to nWords
Print currentDocument.Words(n)
Next
currentDocument.Close
Set currentDocument = Nothing
oWord.Quit
Set oWord = Nothing

No comments:

Post a Comment