View Single Post
  #6   Report Post  
Jean-Guy Marcil
 
Posts: n/a
Default

Ed was telling us:
Ed nous racontait que :

Jean-Guy: Thank you for helping me with the Revisions. InRange is a
pretty neat trick, too. Unfortunately, my document so far has over
900 revisions! To iterate through each one was taking a l-o-o-n-g
time! So I used a piece of code that sets a range to just the page
I'm on, and iterated through the revisions in just that range just to
make sure I have all these concepts right. Much quicker - but it
doesn't catch it!

Showing the revisions, I selected a deleted word. The macro below
sets a range to the selection, sets a range to the page, checks each
revision for Type Deletion, and if it's Deletion checks if the
selection range is in the revision range. All variables set
correctly. The selection is in Revision(5). The macro runs right
over it and ends with no MsgBox! Can you see what I've got wrong?
Ed

Sub Foo_GetMyInfo()

Dim doc As Document
Set doc = ActiveDocument
Dim rng As Range
Set rng = Selection.Range
Dim y As Long
Dim rev As Revision
Dim Pagerange As Range
Set Pagerange = _
doc.Range(doc.Bookmarks("\page").Range.Start, _
doc.Bookmarks("\page").Range.End - 1)

For y = 1 To Pagerange.Revisions.Count
Set rev = Pagerange.Revisions(y)
If rev.Type = wdRevisionDelete Then
If rng.InRange(doc.Revisions(y).Range) = True Then
MsgBox "Revised"
End If
End If
Next y

End Sub



You won't believe this...

Try this line
If rng.InRange(rev.Range) Then
instead of
If rng.InRange(doc.Revisions(y).Range) = True Then

rev.Range represent the actual revision the loop is currently testing,
whereas doc.Revisions(y) represents the document's y'th revisions, which may
not be the same as rev, unless you are on the first page...!

Now, go ahead, and pull your hair!


Note:
I removed the "= True " from the If statement because InRange returns a
Boolean already, so by itself, it is already either true or false.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
ISTOO
Word MVP site:
http://www.word.mvps.org