Highlight does not work for Windows XP?

A

avarghese

Hi

I have a function to "highlight changes" between the currently open document and another document that is stored on a remote fileserver. This is what my code does

Function HighlightChanges(strCompareDoc As String) As Boolea
'*********************************************************************************
'*Purpose: Highlight changes from Prior Draft/Report. This is different from word's defaul
'* behavior during Document Compare. First, it allows for highlighting the changes
'* Second, it removes all place holders for deleted text/tables. Third, after th
'* changes accepted, the highlighting remains
'*Parameters: strCompareDoc (STRING) : Document to Compare ActiveDocument to
'*Return: True - Changes Highlighted False- Error Highlightin
'*Note: Word has issues comparing docs with fields greater than 750 chars in length and wil
'* notify user of this issue. This notice does not effect highlighting except that thos
'* fields are not compared. The field usually is Table of Contents or Index. Use
'* simply needs to click OK
'*********************************************************************************
'*****Declare Variables****
Dim lngI As Long 'Loop Counte
Dim lngRevCount As Long 'Count of Revision

On Error GoTo Error_Handle

'*****Set Mouse Pointer back to normal****
System.Cursor = wdCursorWai

'*****Turn off screen updating****
Application.ScreenUpdating = Fals

On Error Resume Nex
ActiveDocument.Compare strCompareDo
'*****Reset Error Trapping****
On Error GoTo
On Error GoTo Error_Handle

'*****Set Compare Document Options****
With Option
.InsertedTextMark = wdInsertedTextMarkNon
.InsertedTextColor = wdByAutho
.DeletedTextMark = wdDeletedTextMarkHidde
.DeletedTextColor = wdByAutho
.RevisedPropertiesMark = wdRevisedPropertiesMarkNon
.RevisedPropertiesColor = wdAut
.RevisedLinesMark = wdRevisedLinesMarkNon
.RevisedLinesColor = wdAut
End Wit

'*****Count of Revisions****
lngRevCount = ActiveDocument.Revisions.Coun

'*****Loop through Revisions and Highlight them****
For lngI = 1 To lngRevCoun
ActiveDocument.Revisions(lngI).Range.Selec
Selection.Range.HighlightColorIndex = wdYello
Nex

'*****Accept all revisions****
ActiveDocument.Revisions.AcceptAl

'*****Return True****
HighlightChanges = Tru

'*****Set Mouse Pointer back to normal****
System.Cursor = wdCursorNorma

Exit_Point
Exit Functio

Error_Handler
'*****Set Mouse Pointer back to normal****
System.Cursor = wdCursorNorma
HighlightChanges = Fals
Resume Exit_Poin

End Functio

I am not sure where the problem occurs but this piece of code does not work on Windows XP. Currently it is working on Window 2000. I suspect the following line of code is causing the problem

'*****Loop through Revisions and Highlight them****
For lngI = 1 To lngRevCoun
ActiveDocument.Revisions(lngI).Range.Selec
Selection.Range.HighlightColorIndex = wdYello
Nex

but I am not sure.

Please let me know if you have any suggestions. Also let me know if there is a way to detect the version of the Operating System from VBA

I really appreciate any help

Thank
Ale
 
J

John McGhie [MVP - Word]

Hi Asvarghese:

OK, the operating system has nothing to do with this, it will make no
difference at all whether you are working in Windows 200 or Windows XP.

However, the Word version does make a difference: Compare Documents was
dramatically unreliable up to and including Word XP. It wasn't fixed until
Word 2003. Generically, Word XP is a real bug-farm that should never have
been released to production :)

When you say that "this piece of code doesn't work" you're making this game
a bit difficult -- what error message or indication are you getting? Tell
us what is happening "instead".

I see you have two OnError statements there, each doing conflicting things:
which one do you want to use? Chances are the one in use is the first one.

This wouldn't be the first collection I have found in Word that won't work
unless you iterate it backwards: Try this and see if it makes a difference:

For lngI = lngRevCount to 1 count -1

....

And you may find it helpful to use a specific loop redirection to make quite
sure we iterate in the correct loop:

Next lngI...

Hope this helps


This responds to article
from "avarghese" said:
Hi,

I have a function to "highlight changes" between the currently open document
and another document that is stored on a remote fileserver. This is what my
code does:

Function HighlightChanges(strCompareDoc As String) As Boolean
'*****************************************************************************
*****
'*Purpose: Highlight changes from Prior Draft/Report. This is different from
word's default
'* behavior during Document Compare. First, it allows for highlighting
the changes.
'* Second, it removes all place holders for deleted text/tables.
Third, after the
'* changes accepted, the highlighting remains.
'*Parameters: strCompareDoc (STRING) : Document to Compare ActiveDocument to.
'*Return: True - Changes Highlighted False- Error Highlighting
'*Note: Word has issues comparing docs with fields greater than 750 chars in
length and will
'* notify user of this issue. This notice does not effect highlighting
except that those
'* fields are not compared. The field usually is Table of Contents or
Index. User
'* simply needs to click OK.
'*****************************************************************************
*****
'*****Declare Variables*****
Dim lngI As Long 'Loop Counter
Dim lngRevCount As Long 'Count of Revisions

On Error GoTo Error_Handler

'*****Set Mouse Pointer back to normal*****
System.Cursor = wdCursorWait

'*****Turn off screen updating*****
Application.ScreenUpdating = False

On Error Resume Next
ActiveDocument.Compare strCompareDoc
'*****Reset Error Trapping*****
On Error GoTo 0
On Error GoTo Error_Handler

'*****Set Compare Document Options*****
With Options
.InsertedTextMark = wdInsertedTextMarkNone
.InsertedTextColor = wdByAuthor
.DeletedTextMark = wdDeletedTextMarkHidden
.DeletedTextColor = wdByAuthor
.RevisedPropertiesMark = wdRevisedPropertiesMarkNone
.RevisedPropertiesColor = wdAuto
.RevisedLinesMark = wdRevisedLinesMarkNone
.RevisedLinesColor = wdAuto
End With

'*****Count of Revisions*****
lngRevCount = ActiveDocument.Revisions.Count

'*****Loop through Revisions and Highlight them*****
For lngI = 1 To lngRevCount
ActiveDocument.Revisions(lngI).Range.Select
Selection.Range.HighlightColorIndex = wdYellow
Next

'*****Accept all revisions*****
ActiveDocument.Revisions.AcceptAll

'*****Return True*****
HighlightChanges = True

'*****Set Mouse Pointer back to normal*****
System.Cursor = wdCursorNormal

Exit_Point:
Exit Function

Error_Handler:
'*****Set Mouse Pointer back to normal*****
System.Cursor = wdCursorNormal
HighlightChanges = False
Resume Exit_Point

End Function


I am not sure where the problem occurs but this piece of code does not work on
Windows XP. Currently it is working on Window 2000. I suspect the following
line of code is causing the problem:

'*****Loop through Revisions and Highlight them*****
For lngI = 1 To lngRevCount
ActiveDocument.Revisions(lngI).Range.Select
Selection.Range.HighlightColorIndex = wdYellow
Next

but I am not sure.

Please let me know if you have any suggestions. Also let me know if there is a
way to detect the version of the Operating System from VBA.

I really appreciate any help,

Thanks
Alex

--

Please respond only to the newsgroup to preserve the thread.

John McGhie, Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:[email protected]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top