Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2011 22:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/783640 to your computer and use it in GitHub Desktop.
Counts number of words in docx files in a folder.
on error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = "c:\Users\Sean\Desktop\"
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
Set objWord = CreateObject("Word.Application")
iWords = 0
For each folderIdx In files
sFileName = Ucase(folderIdx.name)
if (right(sFileName,4)) = "DOCX" then
Set objDoc = objWord.Documents.Open(sFolder+folderIdx.name)
iWords = iWords + objDoc.Words.Count
objDoc.close
end if
Next
wscript.echo ("Number of words: " & cStr(iWords))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment