Quote:
Originally Posted by macropod
Hi New Daddy,
It's nothing to do with Word 2003. Rather, it's that ComputeStatistics(wdStatisticWords) doesn't count text marked as deleted. Here's a workaround:
Code:
Function CountRevisions(Rng As Range) As Long
Dim i As Long, j As Long, Str As String
With Rng
For i = 1 To .Revisions.Count
If .Revisions(i).Type = wdRevisionInsert Then
j = j + .Revisions(i).Range.ComputeStatistics(wdStatisticWords)
ElseIf .Revisions(i).Type = wdRevisionDelete Then
Str = Trim(.Revisions(i).Range.Text)
Str = Replace(Str, vbCr, " ")
While InStr(Str, " ") > 0
Str = Replace(Str, " ", " ")
Wend
j = j - (UBound(Split(Str, " ")) + 1)
End If
Next
End With
CountRevisions = j
End Function
|
In continuation of this wonderful saga:
It turns out that Word sometimes ignores apparently deleted text in running through revisions. I noticed it after the revision count macro seemingly did not subtract the deleted words. I modified the function so I can see each deleted revision that Word (or the macro here) goes through. Sure enough, Word skips some deleted revision. The behavior is really erratic. Sometimes the same deleted portion would be recognized by the macro, and other times not. I can't really figure out what's causing it. Any idea?
Code:
Function CountNetRevisions(Rng As Range) As Long
Dim i As Long, j As Long, Str As String
With Rng
On Error Resume Next
For i = 1 To .Revisions.Count
If .Revisions(i).Type = wdRevisionInsert Then
j = j + .Revisions(i).Range.ComputeStatistics(wdStatisticWords)
ElseIf .Revisions(i).Type = wdRevisionDelete Then
MsgBox (.Revisions(i).Range.Text)
Str = Trim(.Revisions(i).Range.Text)
Str = Replace(Str, vbCr, " ")
While InStr(Str, " ") > 0
Str = Replace(Str, " ", " ")
Wend
j = j - (UBound(Split(Str, " ")) + 1)
End If
Next
End With
CountNetRevisions = j
End Function