G
Guest
I have this macro but some funcionality is deprecated for W2007.
Have you any suggestion how to make it in other way?
Sub CountAllWords()
'2007 David Sisson
' not suported for W2007 Application.FileSearch deprecated
Dim aDoc As Document
Dim bDoc As Document
Dim sFolderToLookIn As String
Dim TotalWords As Integer
Dim DocWordsCount As Integer
Dim X As Integer
Set bDoc = ActiveDocument
sFolderToLookIn = "C:\My Documents\CountingFolder"
With Application.FileSearch
.NewSearch
.FileName = "*.doc"
.LookIn = sFolderToLookIn
.Execute
For X = 1 To .FoundFiles.Count
Application.ScreenUpdating = False
Set aDoc = Documents.Open(.FoundFiles(X))
DocWordsCount = aDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
IncludeFootnotesAndEndnotes:=True)
bDoc.Range.InsertAfter .FoundFiles(X) & " - " & DocWordsCount & vbCr
TotalWords = TotalWords + DocWordsCount
aDoc.Close savechanges:=wdDoNotSaveChanges
Next X
bDoc.Range.InsertAfter TotalWords & " Total words in " & X & "documents."
End With
Application.ScreenUpdating = True
End Sub
Have you any suggestion how to make it in other way?
Sub CountAllWords()
'2007 David Sisson
' not suported for W2007 Application.FileSearch deprecated
Dim aDoc As Document
Dim bDoc As Document
Dim sFolderToLookIn As String
Dim TotalWords As Integer
Dim DocWordsCount As Integer
Dim X As Integer
Set bDoc = ActiveDocument
sFolderToLookIn = "C:\My Documents\CountingFolder"
With Application.FileSearch
.NewSearch
.FileName = "*.doc"
.LookIn = sFolderToLookIn
.Execute
For X = 1 To .FoundFiles.Count
Application.ScreenUpdating = False
Set aDoc = Documents.Open(.FoundFiles(X))
DocWordsCount = aDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
IncludeFootnotesAndEndnotes:=True)
bDoc.Range.InsertAfter .FoundFiles(X) & " - " & DocWordsCount & vbCr
TotalWords = TotalWords + DocWordsCount
aDoc.Close savechanges:=wdDoNotSaveChanges
Next X
bDoc.Range.InsertAfter TotalWords & " Total words in " & X & "documents."
End With
Application.ScreenUpdating = True
End Sub