Track changes in multiple documents using Word VBA

Track changes in multiple documents using Word VBA

Accept Track Changes

Microsoft Word offers Accept method by which Track changes can be reviewed by the reviewer and make a decision of Accept/Reject. Following code example performs Accept All changes in multiple word documents located in a specific directory:

Code example

Sub AcceptAllTrackChangesInDocumentVBA()
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Select folder..."
        .Show
        If .SelectedItems.Count = 0 Then
            Exit Sub
        Else
            myFolder = .SelectedItems.Item(1)
        End If
    End With
    
    myWildCard = InputBox(prompt:="Enter wild card...")
    
    myDocs = Dir(myFolder & "\" & myWildCard)
    
    While myDocs <> ""
        Dim doc As Document
        Set doc = Documents.Open(FileName:=myFolder & "\" & myDocs, ConfirmConversions:=False)
        doc.Revisions.AcceptAll
        ToggleTrackChanges doc
        doc.Close SaveChanges:=True
        myDocs = Dir()
        Set doc = Nothing
    Wend
    MsgBox "Operation Complete"
End Sub

Supported method

Sub ToggleTrackChangesExample(doc As Document)
    doc.TrackRevisions = Not doc.TrackRevisions
    doc.TrackFormatting = Not doc.TrackFormatting
    doc.TrackMoves = Not doc.TrackMoves
End Sub

Note: wildcard should be supplied as “*.doc” as we want to process all .doc documents within selected directory

Next >> Word Selection Types with VBA code example

Leave a Reply

Your email address will not be published.