H
Howard Kaikow
I find it hard to believe that there is no efficient way to retrieve the
ranges from a proofreadingerrors collection.
Using, For Each, For Next, GoTo or GoToNext is very slow.
My main test document is a 168 page document that has 267 spelling errors.
This is a real document. Only 1 of the spelling errors is really an error,
all the others just are not in the dictionary.
On my very slow system, it takes less than 10 seconds for Word to construct
the collection so I can retrieve .Count.
However, it then takes about 3 minutes to retrieve the ranges.
Since the object returned from the ProofReadingErrors collection is a range,
there sure must be a rather complex structure in the collection to cause
Word to take so much time to return the range.
It appears that each reference to an item in the collection causes Word to
rebuild the collection.
The time for both of the following loops is just about identical.
' yourErrors is a copy of SpellingErrors
QueryPerformanceCounter curQPStart
ReDim rngSpellingError(lngSpellingErrorCount - 1)
For i = 0 To lngSpellingErrorCount - 1
Set rngSpellingError(i) = yourErrors(i + 1)
Next i
QueryPerformanceCounter curQPEnd
lngTime = (curQPEnd - curQPStart) / dblQPFreq * 1000
Debug.Print "Copying ranges from collection: " & lngTime
QueryPerformanceCounter curQPStart
ReDim rngSpellingError(lngSpellingErrorCount - 1)
With ActiveDocument.Content
For i = 0 To lngSpellingErrorCount - 1
Set rngSpellingError(i) = .SpellingErrors(i + 1)
Next i
End With
QueryPerformanceCounter curQPEnd
lngTime = (curQPEnd - curQPStart) / dblQPFreq * 1000
Debug.Print "Using ActiveDocument.Content, Copying ranges from
collection: " & lngTime
ranges from a proofreadingerrors collection.
Using, For Each, For Next, GoTo or GoToNext is very slow.
My main test document is a 168 page document that has 267 spelling errors.
This is a real document. Only 1 of the spelling errors is really an error,
all the others just are not in the dictionary.
On my very slow system, it takes less than 10 seconds for Word to construct
the collection so I can retrieve .Count.
However, it then takes about 3 minutes to retrieve the ranges.
Since the object returned from the ProofReadingErrors collection is a range,
there sure must be a rather complex structure in the collection to cause
Word to take so much time to return the range.
It appears that each reference to an item in the collection causes Word to
rebuild the collection.
The time for both of the following loops is just about identical.
' yourErrors is a copy of SpellingErrors
QueryPerformanceCounter curQPStart
ReDim rngSpellingError(lngSpellingErrorCount - 1)
For i = 0 To lngSpellingErrorCount - 1
Set rngSpellingError(i) = yourErrors(i + 1)
Next i
QueryPerformanceCounter curQPEnd
lngTime = (curQPEnd - curQPStart) / dblQPFreq * 1000
Debug.Print "Copying ranges from collection: " & lngTime
QueryPerformanceCounter curQPStart
ReDim rngSpellingError(lngSpellingErrorCount - 1)
With ActiveDocument.Content
For i = 0 To lngSpellingErrorCount - 1
Set rngSpellingError(i) = .SpellingErrors(i + 1)
Next i
End With
QueryPerformanceCounter curQPEnd
lngTime = (curQPEnd - curQPStart) / dblQPFreq * 1000
Debug.Print "Using ActiveDocument.Content, Copying ranges from
collection: " & lngTime