Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Tables / February 2006

Tip: Looking for answers? Try searching our database.

Word Count on over 7000 word docs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sujal - 26 Feb 2006 04:45 GMT
How can I extract word count of over 7000 word docs and place the answer in
Excel.

Also need to get the word count of the doc into the doc, how can I do that
automatically for over 7000 docs?

Thanks

Sujal
Doug Robbins - Word MVP - 26 Feb 2006 09:13 GMT
The following will create a new document containing the information that you
can then copy and paste into Excel.  It will however include punctuation
marks, etc. in the count:

Dim MyPath As String
Dim MyName As String
Dim source As Document
Dim target As Document
Dim Wordcount As Long

Set target = Documents.Add

'let user select a path
With Dialogs(wdDialogCopyFile)
   If .Display() <> -1 Then Exit Sub
   MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
   MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
   Set source = Documents.Open(MyName)
   Wordcount = source.Words.Count
   source.Range.InsertAfter vbCr & "This document contains " & Wordcount &
" words (including punctuation and paragraph marks)."
   target.Range.InsertAfter "The document " & MyName & " contains " &
Wordcount & " words (including punctuation and paragraph marks)." & vbCr
   source.Save
   source.Close
   MyName = Dir
Loop
target.Activate

If you want to exclude punctuation and paragraph marks, the following should
do that, but will take a lot longer:

Dim MyPath As String
Dim MyName As String
Dim source As Document
Dim target As Document
Dim Wordcount As Long

Set target = Documents.Add

'let user select a path
With Dialogs(wdDialogCopyFile)
   If .Display() <> -1 Then Exit Sub
   MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
   MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
   Set source = Documents.Open(MyName)
   Wordcount =
source.Content.ComputeStatistics(Statistic:=wdStatisticWords,
IncludeFootnotesAndEndnotes:=True)
   source.Range.InsertAfter vbCr & "This document contains " & Wordcount &
" words."
   target.Range.InsertAfter "The document " & MyName & " contains " &
Wordcount & " words." & vbCr
   source.Save
   source.Close
   MyName = Dir
Loop
target.Activate

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> How can I extract word count of over 7000 word docs and place the answer
> in
[quoted text clipped - 6 lines]
>
> Sujal
Sujal - 27 Feb 2006 03:26 GMT
Thanks Doug! This solved the problem.

Thank again for your help!

Sujal

> The following will create a new document containing the information that you
> can then copy and paste into Excel.  It will however include punctuation
[quoted text clipped - 91 lines]
> >
> > Sujal
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.