Using "For Each" to loop a collection does not allow access to each revision item (304020)



The information in this article applies to:

  • Microsoft Office Word 2003
  • Microsoft Word 2002

This article was previously published under Q304020

SYMPTOMS

When you use a For Each statement to loop the Activedocument.Range.Revisions collection in Microsoft Word, the expected number of Revision objects is not always returned.

The Revisions.Count reflects more objects than the For Each actually returns.

CAUSE

When the Track Changes option is not selected, it is possible to split a revision (a revision is a contiguous range in a document). There are multiple ways to cause a revision to no longer be contiguous, for example, typing additional characters in an existing revision or inserting a section break in the middle of an existing revision.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this problem, use a For Next loop that uses the Revisions collection and ActiveDocument.Range.Revisions.Count. This allows you to access the entire collection.
For i = 1 To ActiveDocument.Revisions.Count
   MsgBox "Format Description: " _
        & ActiveDocument.Revisions(i).FormatDescription & " Index number: " _
        & ActiveDocument.Revisions(i).Index & " Member number in Count: " & i
Next i
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug KB304020