![]() |
|
|
|
#1
|
|||
|
|||
|
I want to compare a large number of documents, in different folders, to see their word counts.
So far, using several different search methods and programs, all I've been able to do is come up with lists of docs that show each doc's size in kilobytes. This isn't accurate enough because the kb count is 'rounded'. Ideally, I could institute a search for *.doc and have the result show every document's word total. Anyone know a way of doing this? I'm running XPP and Word 2003. Search apps I've tried are 'Search Everything', Agent Ransack and its full version, File Locator Pro. |
|
#2
|
|||
|
|||
|
This will require a vba procedure (macro) that I am not competent to write. It is not something built into Word. See duplicate post at http://answers.microsoft.com/en-us/o...1425d207#_self
There is nothing wrong with asking the same question in multiple locations, but please let people know about the other spot to avoid duplication of effort. |
|
#3
|
||||
|
||||
|
You could try a macro like the following in an empty document:
Code:
Sub GetWordCounts()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
Dim Rng As Range, Shp As Shape, iShp As InlineShape, i As Long
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
i = 0
'Get word counts from the document body, endnotes, & footnotes
For Each Rng In .StoryRanges
Select Case .Type
Case wdMainTextStory, wdEndnotesStory, wdFootnotesStory
i = i + Rng.ComputeStatistics(wdStatisticWords)
End Select
Next
'Get word counts from textboxes, etc. in the document body
For Each Shp In .Shapes
With Shp
If Not .TextFrame Is Nothing Then
i = i + .TextFrame.TextRange.ComputeStatistics(wdStatisticWords)
End If
End With
Next
For Each iShp In .InlineShapes
With iShp
i = i + .Range.ComputeStatistics(wdStatisticWords)
End With
Next
.Close SaveChanges:=False
End With
ThisDocument.Range.InsertAfter strFile & vbTab & i & vbCr
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Note 1: The macro only processes one folder at a time. Note 2: The macro processes the document body, endnotes, footnotes and textboxes in the document body (not in headers & footers); you can omit any of the first three you might not be interested in by editing the line - Case wdMainTextStory, wdEndnotesStory, wdFootnotesStory and, for textboxes, etc., by omitting the corresponding For Each ... Next loops.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#4
|
|||
|
|||
|
When run on a folder that contains primary merge documents, the procedure is interrupted to confirm links. When run on a folder that contains no word documents nothing is returned.
I made the mistake of putting these in a module in my normal.dotm. It put the text into normal.dotm (as you said it would). Changing ThisDocument to ActiveDocument eliminated that problem. I was worried that ActiveDocument might be the document being counted, but it was the document that was open when I ran the macro. |
|
#5
|
||||
|
||||
|
hi Charles,
You could reduce the interruption issues by adding: Application.DisplayAlerts = False after: Application.ScreenUpdating = False The lack of output for a folder containing no documents is as I would expect - the macro is only coded to report documents.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#6
|
|||
|
|||
|
Thanks, this isn't something I have any use for, but I was interested in the code and really like your folder picker.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| search on multiple word documents | Guy Roth | Word | 7 | 03-06-2017 01:31 PM |
How can I count multiple usage of the same words?
|
coffee_king | Word VBA | 1 | 03-24-2012 07:52 PM |
| Word 2010 / Master Index / Multiple Documents | bawrites | Word | 0 | 08-09-2011 11:02 AM |
How to count multiple values in a single cell, except zero?
|
iuliandonici | Excel | 1 | 04-13-2011 09:45 PM |
Count with multiple conditions
|
bundy5150 | Excel | 4 | 02-22-2011 10:00 AM |