View Single Post
 
Old 07-26-2012, 11:46 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
The macro has its own folder browser, which lets you choose the folder to process. The output, in the document holding the macro, consists of the document names and their word counts.

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]
Reply With Quote