View Single Post
  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

Using the following may give a more accurate count:

Dim i As Long
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document

PathToUse = "C:\Documents\"

'Error handler to handle error generated whenever
'the FindReplace dialog is closed

On Error Resume Next

'Initiate the counter i

i = 0

'Close all open documents before beginning

Documents.Close SaveChanges:=wdPromptToSaveChanges

'Set the directory and type of file to batch process

myFile = Dir$(PathToUse & "*.doc")

While myFile ""

'Open document
Set myDoc = Documents.Open(PathToUse & myFile)

'Increment the counter i with the number of words in the document

i = i + myDoc.BuiltInDocumentProperties(wdPropertyWords)

myDoc.Close SaveChanges:=wdDoNoSaveChanges

'Next file in folder

myFile = Dir$()

Wend

MsgBox "Total number of words is " & i & "."

The issue with combining the documents is to get them in the correct order.
If you have a list of the documents in another document, one to a paragraph,
a macro can be used to iterate through that list, opening each document in
turn, and then inserting its content into another documnet after the
previous document that was inserted there.

The following code should do it:

Dim source As Document, target As Document, listdoc As Document
Dim i As Long
Dim myFile As Range
Dim PathToUse As String

PathToUse = "C:\Documents\test\"

'listdoc is the document that contains the list of the other documents
'Start with that document open
Set listdoc = ActiveDocument
'Open a new document
Set target = Documents.Add
For i = 1 To listdoc.Paragraphs.Count
Set myFile = listdoc.Paragraphs(i).Range
myFile.End = myFile.End - 1
Set source = Documents.Open(PathToUse & myFile.Text)
target.Range.Select
Selection.Collapse wdCollapseEnd
Selection.FormattedText = source.Range
source.Close wdDoNotSaveChanges
Next i


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
"Donald C. McNeilly" wrote in message
...
Thank you! Thank you! Worked like a charm once the user got his head
around it. Only took 25 minutes. THe total number was a bit of a stunner
though, over 900,000. I did a double check of all the As and came up with
33,000 manual and 43,000 using the macro. Any ideas why this might be? Can
always discount the macro count by 25% but...

Now is there any way of combining docs say all the A into one?

Thanks again

You wrote: "If you put all of the documents in one folder and modify the
string in the
PathToUse statement in the following macro to point to that folder and
then
you run this macro, it will count the words in all of the documents. For
1200 documents, I would put the kettle on to boil before you start"