Share via

Find nested tracked changes with VBA

Anonymous
2011-07-18T10:21:19+00:00

Is there a non-resource-draining way to find 'nested revisions' in a document -- that is, spots where one reviewer has made a tracked insertion and another reviewer has deleted it (also tracked). So far the only method I've come up with is this:

Dim ch As Range

For Each ch In ActiveDocument.Characters

    If ch.Revisions.Count > 1 Then ch.HighlightColorIndex = wdBrightGreen

Next

....which works, but as you can imagine, it not quick, and turns up a lot of false positives (flags every table row with multiple revisions in a cell -- even if not overlapping -- as nested). Is there a better way? Trying to cycle through revisions collection itself throws an error (object not available).

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2011-07-20T15:21:34+00:00

    The problem occurs because we compare 2 ranges, not only one.

    Should be solvable, can you send me a sample file?

    Andreas.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-07-20T10:32:38+00:00

    Nice, and very fast. But I notice a new problem: both your macro and mine STOP flagging overlaps when they reach a table!

    It doesn't even seem possible to skip tables altogether. Adding

           If Not R.Range.Information(wdWithinTable)

    after the Set statement changes nothing.

    Any ideas?

    Mark

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2011-07-20T07:17:58+00:00

    Why not test the positions of the range of each revision?

    Andreas.

    Sub Test()

      Dim R As Revision

      Dim Pos() As Long

      Dim i As Long, j As Long

      With ActiveDocument

        ReDim Pos(1 To .Revisions.Count, 1 To 2)

        For i = 1 To .Revisions.Count

          Set R = .Revisions(i)

          Pos(i, 1) = R.Range.Start

          Pos(i, 2) = R.Range.End

          For j = 1 To i - 1

            If (Pos(i, 1) >= Pos(j, 1) And Pos(i, 1) <= Pos(j, 2)) Or _

               (Pos(i, 2) >= Pos(j, 1) And Pos(i, 2) <= Pos(j, 2)) Then

              'Overlaps

              If Pos(i, 1) < Pos(j, 1) Then

                .Range(Pos(j, 1), Pos(i, 2)).HighlightColorIndex = wdBrightGreen

              Else

                .Range(Pos(i, 1), Pos(j, 2)).HighlightColorIndex = wdBrightGreen

              End If

            End If

          Next

        Next

      End With

    End Sub

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2011-07-19T16:23:15+00:00

    The problem with the revisions collection is that it seems to like only nice neat small revisions. The code below works with simple revisions in the middle of text but chokes (5825 obj not avail) when it looks at more complex types:

    Dim rv As Revision

    For Each rv In ActiveDocument.Revisions

        If rv.Range.Revisions.Count > 1 Then

            rv.Range.Revisions(2).Range.HighlightColorIndex = wdBrightGreen

        End If

    Next

    I don't see what your suggested code is trying to do. I don't need the macro to query me on each revision it sees. I want it to highlight where a tracked insertion and a tracked deletion overlap.

    MT

    Was this answer helpful?

    0 comments No comments
  5. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2011-07-19T14:09:35+00:00

    And what is the problem with the Revisions collection?

    Andreas.

    Sub Test()

      Dim R As Revision

      With ActiveDocument

        '.TrackRevisions = True

        .ShowRevisions = True

        For Each R In .Revisions

          If MsgBox(R.Author & " " & R.Date & " => " & R.Range.Text, vbOKCancel) <> vbOK Then Exit Sub

        Next

      End With

    End Sub

    Was this answer helpful?

    0 comments No comments