Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Location
    Santa Barbara CA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Index of Tracked Changes

    I'd like to create an index to (or table of) Tracked Changes, so that at the front of a document I can let the reader know that they'll find changes at certain paragraph numbers. In particular, I'd like the index to show: date; time; paragraph number (sorted by the latter).

    I've come across something in MS Help that indicates I could show page numbers (by setting the appropriate flags), but I assume I'll need to get into VBA to get access to the other pieces of data about each change.

    I expect I'll need to write a macro, and the main thing I need help with initially is finding out how I can capture 1) the info that appears in the balloon when you hover over a tracked change; and 2) the paragraph number instead of the page number.

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Index of Tracked Changes

    Hi,

    The following code should more than get you started.[img]/w3timages/icons/grin.gif[/img]
    Don't run this sample though, in a document with too many tracked changes, as it displays a message box for each change!

    You can easily though take the information that's being displayed in the message boxes, and make it the data for your index table.

    There is a catch with regard to the paragraph number, as I don't think there's any direct way to get that info. I recall there was a thread (here or in the old Lounge?) in which a couple of functions were posted for getting this info - I believe they were rather slow though. I've settled for page number here. Also note that the revisions listing will automatically sort from start of doc to end.

    <pre>Sub GetChangesInfo()
    Dim objDocRevs As Revisions
    Dim lngRevCt As Long
    Dim n As Long
    Dim strRevNum As String
    Dim strRevAuth As String
    Dim strRevDate As String
    Dim strRevPage As String

    Set objDocRevs = ActiveDocument.Revisions
    lngRevCt = objDocRevs.Count
    '(lngRevCt will also be used to determine number of table rows)

    For n = 1 To lngRevCt
    strRevNum = Str$(objDocRevs(n).Index)
    strRevAuth = objDocRevs(n).Author
    strRevDate = Str$(objDocRevs(n).Date)
    strRevPage = Str$(objDocRevs(n).Range.Information(wdActiveEndPa geNumber))
    MsgBox "Revision number: " & strRevNum & _
    vbCr & "Author: " & strRevAuth & _
    vbCr & "Date and time: " & strRevDate & _
    vbCr & "On page number: " & strRevPage
    Next n
    End Sub
    </pre>

    Gary

  3. #3
    New Lounger
    Join Date
    Jan 2001
    Location
    Santa Barbara CA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Index of Tracked Changes

    No wonder they call you MVP! The best I'd hoped for was a tip on where to find the data -- the whole macro was beyond my dreams! I don't expect to ever be able to return the favor directly to you, but you've invested it into the favor bank from which I'll be able to repay it to someone in some way someday. Thanks, Gary.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Index of Tracked Changes - Full Version

    Yikes! - thanks for the response, and you're welcome. And this is before I posted the rest of this macro.
    Probably I should have shown more restraint, but couldn't resist finishing this one[img]/w3timages/icons/oink.gif[/img][img]/w3timages/icons/cool.gif[/img], so anyway here it is:

    <pre>Sub GetChangesInfo()
    Dim objDocRevs As Revisions
    Dim objIndex As Table
    Dim lngRevCt As Long
    Dim n As Long
    Dim strRevNum As String
    Dim strRevAuth As String
    Dim strRevDate As String
    Dim lngRevType As Long
    Dim strRevType As String
    Dim strRevPage As String

    Set objDocRevs = ActiveDocument.Revisions
    lngRevCt = objDocRevs.Count
    'Create table at start of document:
    With Selection
    .HomeKey Unit:=wdStory
    If .Information(wdWithInTable) Then
    MsgBox "Cannot insert table - there's already a table at start of document"
    Exit Sub
    End If
    End With
    Set objIndex = ActiveDocument.Tables.Add(Range:=Selection.Range, _
    NumRows:=(lngRevCt + 1), _
    NumColumns:=5)
    With objIndex
    .Cell(1, 1).Range.Text = "Revision Number"
    .Cell(1, 2).Range.Text = "Author"
    .Cell(1, 3).Range.Text = "Date and Time"
    .Cell(1, 4).Range.Text = "Revision Type"
    .Cell(1, 5).Range.Text = "Page Number"
    .Rows(1).Range.Font.Bold = True
    End With

    For n = 1 To lngRevCt
    strRevNum = Str$(objDocRevs(n).Index)
    strRevAuth = objDocRevs(n).Author
    strRevDate = Str$(objDocRevs(n).Date)
    lngRevType = objDocRevs(n).Type
    If lngRevType = 1 Then
    strRevType = "Insertion"
    ElseIf lngRevType = 2 Then
    strRevType = "Deletion"
    End If
    strRevPage = Str$(objDocRevs(n).Range.Information(wdActiveEndPa geNumber))
    'Write results to appropriate index table row:
    With objIndex
    .Cell((n + 1), 1).Range.Text = strRevNum
    .Cell((n + 1), 2).Range.Text = strRevAuth
    .Cell((n + 1), 3).Range.Text = strRevDate
    .Cell((n + 1), 4).Range.Text = strRevType
    .Cell((n + 1), 5).Range.Text = strRevPage
    End With
    Next n
    End Sub</pre>


  5. #5
    rgc
    Guest

    Re: Index of Tracked Changes - Full Version

    Gary:
    I have been playing with your most interesting program. There appears to be a problem with the Revisions object however - it seems to barf if the revision is within a table. It returns "Error 5852 Requested Object is Not Available" This occurs during the For...Next loop - it appears that the ".Count" property works as the index table is created with apparently the correct number of rows (I say "apparently" because my test document is quite long with a number of changes and I don't have the time at present to do an exhaustive debug).

    Do you have any ideas on how to circumvent this problem?

    regards
    Grant Cartledge

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Index of Tracked Changes - Full Version

    Hi Grant,

    I hadn't originally tested it on a document that contained revisions in tables, and now that I do, I get the same error you're getting.

    As you say, the .Count property is working correctly, but when you loop through the collection of Revisions, you get the error as soon as you hit a Revision that's in a table.

    I think it's fair to call this a (nasty) bug. My first thought was to do some sort of test whether the Revision is in a table, but no use as you get the error as soon as you even mention the revision![img]/w3timages/icons/yikes.gif[/img]

    Unfortunately so far that was my only thought[img]/w3timages/icons/crazy.gif[/img].
    Actually, you could first convert all the tables in the given document to text. But then you wouldn't want to run this macro on a live document but rather on a copy.

    (And this now makes Item #8 of the "I Hate Track Changes Bible"!)[img]/w3timages/icons/dragon.gif[/img]

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •