user3311071
user3311071

Reputation: 35

Macro to reverse tracked changes in Word?

A lot of my work involves negotiating tech contracts, and the industry convention is that the two parties send each other marked-up MS Word documents showing the changes they'd like. This often happens multiple times before it is agreed.

Often a paragraph will come back with many insertions/deletions, which we don't want to accept. Again, the convention is that even rejecting these changes needs to be marked up, so that each of their individual insertions (blue text) must now be marked as deletions (red strikeout) and vice versa.

Does anyone know of a macro that can do this? Or know how to write one? I've spent hours searching online and trying to teach myself to code one, but I'm getting nowhere!

I think the easiest way would be to alter the Revision.Type property of each Revision in the selection from wdRevisionDelete to wdRevisionInsert (or vice versa), but this seems to be a read-only property.

I've tried assigning deleted text to a string, accepting the change, and then inserting it, but cannot get it to go in the right place. I also can't find how to delete the inserted text, so can't get anywhere with the other side of the equation.

Is there a way to do this? Ideally, I'd be able to select some text, run the macro, and have each revision 'flipped'. It sounds so simple, but I cannot find a way. It would honestly save me hours per month, so I'd be extremely grateful if anyone could help.

Thanks in advance! James

Upvotes: 3

Views: 2303

Answers (1)

Tim Williams
Tim Williams

Reputation: 166341

Normally I wouldn't answer a question with no code, but this seemed interesting.

This worked for me (select the range you want to work on before running):

EDIT2: now handles adjoining edits without adding extra text

Sub FlipDeletesAndInserts()

    Dim rng As Range, rev As Revision, rngRev As Range
    Dim colDel As New Collection, colIns As New Collection
    Dim step As Long, txt As String

    If ActiveDocument.TrackRevisions Then
        Debug.Print "Tracked..."
    Else
        MsgBox "Track changes is not on!"
        Exit Sub
    End If

    Set rng = Selection.Range 'operate on the selected text

    'Collect all of the revisions before changing anything,
    '  otherwise the new changes also will be processed!
    For Each rev In rng.Revisions
        If rev.Type = wdRevisionDelete Then colDel.Add rev
        If rev.Type = wdRevisionInsert Then colIns.Add rev
    Next rev

    For Each rev In colIns
        Set rngRev = rev.Range
        Debug.Print "Inserted:", rngRev.Text
        rev.Accept    'accept the new text
        rngRev.Delete '...then delete it
    Next rev

    For Each rev In colDel
        Set rngRev = rev.Range
        'EDIT: grab the text before accepting...
        txt = rngRev.Text
        Debug.Print "Deleted:", txt
        rev.Accept 'EDIT:added
        'insert the same deleted text as an insert
        '  immediately after the deletion
        rngRev.InsertAfter txt
    Next rev

End Sub

Before and after:

enter image description here

Upvotes: 2

Related Questions