![]() |
#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] |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
search on multiple word documents | Guy Roth | Word | 7 | 03-06-2017 01:31 PM |
![]() |
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 |
![]() |
iuliandonici | Excel | 1 | 04-13-2011 09:45 PM |
![]() |
bundy5150 | Excel | 4 | 02-22-2011 10:00 AM |