1
votes

I need to convert tracked changes in Microsoft Word into actual text with the underline/strikethrough. I have had difficulties in dealing with tracked changes with cross-references.

For instance, if a cross reference is updated, from paragraph 5 to 6, it would appear as "65" [the 6 is underlined, but stackoverflow doesn't have that formatting option] I want to retain the 5 as raw text only, but keep the 6 as a cross-reference field.

I've gotten as far as the following macro which will do what I want if the cross reference has been /replaced/ with a new cross reference. However, it still does not work properly if the cross reference was only updated. Any help would be greatly appreciated:

Sub TypeAndStrike()

Dim chgAdd As Word.Revision
Dim Colour
Colour = RGB(255, 0, 0) ' Set the color to change the changes to.
'PD Colors: Black (0, 0, 0), Red (255, 0, 0), Green (0, 255, 0), Blue (0, 0, 255), Brown (165, 42, 42)

Dim SkipNext As Integer

' disable tracked revisions.
If ActiveDocument.Revisions.Count = 0 Then
MsgBox "There are no revisions in this document", vbOKOnly
Else
ActiveDocument.TrackRevisions = False

For Each chgAdd In ActiveDocument.Revisions
If chgAdd.Type = wdRevisionDelete Then ' It's a deletion, so make it strike through and then reject the change (so the text isn't lost).

    SkipNext = 0
    chgAdd.Range.Select ' move insertion point

    chgAdd.Range.Font.StrikeThrough = True
    chgAdd.Range.Font.Color = Colour
        For Each testRange In Selection.Range.Fields ' Replace cross-refs with >text
        testRange.Select
        If Selection.Range = chgAdd.Range Then
            SkipNext = 1
        End If
        Selection.TypeText Text:=Selection.Text
        Next
    If SkipNext = 0 Then
    chgAdd.Range.Select
    chgAdd.Reject
    End If

ElseIf chgAdd.Type = wdRevisionInsert Then ' It's an addition, so underline it.

    chgAdd.Range.Font.Underline = wdUnderlineSingle
    chgAdd.Range.Font.Color = Colour
    chgAdd.Accept
Else
    chgAdd.Range.Select ' move insertion point
End If

Next chgAdd
End If
End Sub
1

1 Answers

0
votes

I haven't worked a lot with Revisions, so my suggestion may have drawbacks, however, it occurs to me that you might be able to do something with Field.Result.

A cross-reference is a REF field, under the covers - press Alt+F9 and you can toggle on the field code view to see it.

When code queries ActiveDocument.Fields([index]).Result a RANGE object is returned (a Range is returned for any Field.Result). Result.Text returns the visible result as plain text - in your example 65.

In and of itself, that's not useful. But if you combine it with, perhaps, Result.Revisions.Count you can find out how many revisions (if any) are stored in the field. Using your example, Count returns two and you know the first (left) is the change and the second (right) is the original. That should let you figure out what the value should be. You could then remove the field (Field.Unlink) and write the desired result to the document?