Thursday, June 24, 2010

How to get Author details from Track Changes using VBA

Word VBA - extract Revision Author information

If you want to know the details of track revisions, for example, Author name etc the following code will help you:

Sub Get_TrackRevision_Author()

Dim oRev As Revision
Dim oRange As Range

' -----------------------------------------------------------
' Change the line below to suit your needs
' -----------------------------------------------------------
Set oRange = Selection.Range

' -----------------------------------------------------------
' Coded by Shasur for http://vbadud.blogspot.com
' -----------------------------------------------------------

For Each oRev In oRange.Revisions
    MsgBox oRev.Range.Text & " " & oRev.Author
Next oRev


End Sub


The following code provides you more information (like if the comment is inserted / deleted)

If oRev.Type = wdRevisionDelete Then
        MsgBox oRev.Range.Text & " deleted by " & oRev.Author
    ElseIf oRev.Type = wdRevisionInsert Then
        MsgBox oRev.Range.Text & " added by " & oRev.Author
    Else
        MsgBox oRev.Range.Text & " " & oRev.Author
    End If

If you want to know Date of Revision using VBA then the following can be added

MsgBox oRev.Range.Text & " " & oRev.Author & " " & oRev.Date

2 comments:

  1. When i run the above code in a word file it gets error while there is track changes in table, how to avoid this error. Error is 'Method 'author' in object 'Revision' failed.

    ReplyDelete
  2. Hi Iniyal

    Can you try by making a revision (either by inserting/ deletion) the comment.

    Just want to know if there is a problem with that particular table / revision

    Please also mention the versin of Word you are using

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.