View Single Post
  #2   Report Post  
Greg Maxey
 
Posts: n/a
Default

AFAIK they have to be opened, but it can be automated. The macro below is
relatively crude in the way the data is displayed, but it will work.

Put all of the files in a dedicated folder. I used C:\Batch Files.

Create a new blank document with a single row two column table. Label the
left column Document Name and the right column Word count.

Put this macro in the document and run it:

Sub BacthFileCountWords()
'Compiled by Greg Maxey

Dim MyFile As String
Dim PathToUse As String
Dim pDocName As String
Dim pWordCount As Long
Dim Counter As Long
Dim myDoc As Document
Dim i As Long

'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000) '1000 is arbitrary

'Specify folder containing files
PathToUse = "C:\Batch Folder\"
'Loop through all the files of *.doc type in the directory by using Dir$
function
MyFile = Dir$(PathToUse & "*.doc")
'For each file found add to the array
Do While MyFile ""
DirectoryListArray(Counter) = MyFile
'Get the next file name
MyFile = Dir$
Counter = Counter + 1
Loop

'Reset the size of the array without losing its values by using Redim
Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
Application.ScreenUpdating = False
i = 2
For Counter = 0 To UBound(DirectoryListArray)
Set myDoc = Documents.Open(FileName:=PathToUse &
DirectoryListArray(Counter), _
Visible:=False)
With myDoc
pDocName = .Name
pWordCount = .Words.Count
.Save
.Close
End With
ActiveDocument.Tables(1).Cell(i, 1).Range.Text = pDocName
ActiveDocument.Tables(1).Cell(i, 2).Range.Text = pWordCount
i = i + 1
ActiveDocument.Tables(1).Rows.Add
Next Counter
ActiveDocument.Tables(1).Rows.Last.Delete
Application.ScreenUpdating = True
End Sub


Masters, if you can offer a more graceful way of displaying the data please
advise.



--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Henley writer wrote:
I am expecting to receive a batch of about 700 files and will need to
do a word count on each of them. How can I do this automatically? I
don't want to have to open each one, do a wordcount and then write
down the answer! Is it possible to generate a list of their
individual word counts without opening them? I can make sure they are
all in one folder if necessary.

Thanks for your help!