Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 23rd, 2008, 06:21 PM
Registered User
 
Join Date: Oct 2008
Location: , , .
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
WordBasic.ShowComments
WordBasic.ShowFormatting
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

Reply With Quote
  #2 (permalink)  
Old October 24th, 2008, 01:05 AM
Friend of Wrox
Points: 2,950, Level: 22
Points: 2,950, Level: 22 Points: 2,950, Level: 22 Points: 2,950, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 788
Thanks: 1
Thanked 51 Times in 47 Posts
Default

Hi

Here is a hint

Code:
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
            ActiveDocument.Revisions(i).Accept
            i = i - 1
            iMax = iMax - 1
        End If
    End If
Next i
ActiveDocument.TrackRevisions = True

End Sub
Cheers
Shasur

http://www.dotnetdud.blogspot.com

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

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!

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08:58 AM



All times are GMT -4. The time now is 02:59 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.