Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 07-26-2012, 11:46 PM
macropod's Avatar
macropod macropod is offline Word count in multiple documents Windows 7 64bit Word count in multiple documents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
search on multiple word documents Guy Roth Word 7 03-06-2017 01:31 PM
Word count in multiple documents 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
Word count in multiple documents How to count multiple values in a single cell, except zero? iuliandonici Excel 1 04-13-2011 09:45 PM
Word count in multiple documents Count with multiple conditions bundy5150 Excel 4 02-22-2011 10:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft