Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 23rd, 2008, 06:21 PM
Registered User
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Macro to highlight changes

Due to ridiculous work requirements, I have to highlight any insertions in a Word document. Track changes will change font color, but will not highlight text, so I need a macro. What I have is the following, but it always hangs up and never completes. I've tested in several documents (after doing a compare and merge) and there doesn't seem to be any rhyme or reason for the stopping points. Any thoughts or advice?

Sub Macro10()
Dim myRev As Object
Dim i As Integer
    With Options
        .InsertedTextMark = wdInsertedTextMarkBold
        .InsertedTextColor = wdBlue
        .DeletedTextMark = wdDeletedTextMarkStrikeThrough
        .DeletedTextColor = wdRed
        .RevisedPropertiesMark = wdRevisedPropertiesMarkNone
        .RevisedPropertiesColor = wdByAuthor
        .RevisedLinesMark = wdRevisedLinesMarkOutsideBorder
        .RevisedLinesColor = wdAuto
        .CommentsColor = wdByAuthor
        .RevisionsBalloonPrintOrientation = wdBalloonPrintOrientationPreserve
    End With
For i = 1 To 1500
On Error Resume Next
Set myRev = Selection.NextRevision
If Not (myRev Is Nothing) Then
    If myRev.Type = wdRevisionInsert Then Selection.Range.HighlightColorIndex = wdYellow
    If myRev.Type = wdRevisionInsert Then Selection.Range.Revisions.AcceptAll
End If
Next i
End Sub

Old October 24th, 2008, 01:05 AM
Friend of Wrox
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts


Here is a hint

Sub HLight_Inserts()

Dim i As Long
Dim iMax As Long
Dim bAccept As Boolean ' Set this to True if you want to accept revision

ActiveDocument.TrackRevisions = False
' ----------------------------
' Set bAccept  = True if Insertions to be Accepted
' ----------------------------
bAccept = False
' ----------------------------

iMax = ActiveDocument.Revisions.Count
For i = 1 To iMax
    If i > iMax Then Exit For
    Debug.Print ActiveDocument.Revisions(i).Type
    If ActiveDocument.Revisions(i).Type = wdRevisionInsert Then
        ActiveDocument.Revisions(i).Range.HighlightColorIndex = wdYellow
        If bAccept = True Then
            i = i - 1
            iMax = iMax - 1
        End If
    End If
Next i
ActiveDocument.TrackRevisions = True

End Sub


VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Old October 24th, 2008, 11:46 AM
Registered User
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Shasur, thanks much!

While it was incredibly helpful, I do hope maybe you can provide some additional support.

I think this may be a problem with Word itself, so I don't know if there's a workaround. These documents have tables in them as well. Neither your procedure nor mine will move through a table if a row or column has been deleted. Trying it manually, it gets to a deleted a row or column, and sees that as the end of document, and asks if you'd like to return to the top. Fortunately, these are closer to the end than the beginning, but still, it's a hassle to highlight manually. Any thoughts on this?

*Edit.... It went through my first table just fine, which had deleted columns. The second table, it would do anything, not even highlight changes prior to a deleted column or row. The only things between the stopping point and the table are deleted text (which it has ignored on all other pages) and format changes (same ones ignored on previous changes). It did state an issue with:
Debug.Print ActiveDocument.Revisions(i).Type

Also, the document is 51 pages with changes tracked. Your code moved through 49 pages........in ten minutes. Do you think there may be a way to speed it up at all? If not, it's still much, much faster than doing it by hand.

Thanks again!

Similar Threads
Thread Thread Starter Forum Replies Last Post
calling to xlam macro from macro inside xlsb SteveB Excel VBA 0 June 30th, 2008 06:43 PM
Highlight Datagrid Cell derekl ASP.NET 1.0 and 1.1 Basics 1 July 28th, 2006 06:12 AM
How to highlight in Excel haiying Excel VBA 5 April 6th, 2005 01:29 PM
how to highlight in Powerpoint haiying Access VBA 6 April 6th, 2005 08:04 AM
Highlight record JpJoe Access 4 January 28th, 2005 09:58 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.