Accepting deletions in a selected area

R

robot

Hello,

I use the following code to accept all deletions in the selected area of a
document with revision marks:

Dim r As Revision
For Each r In Selection.Range.Revisions
If r.Type = wdRevisionDelete Then r.Accept
Next r

However, no matter what area I selected, the above code always accepts all
deletions in the *entire* document. What went wrong?

I use Office XP and Win XP pro. Suggestions are most welcome.
 
J

Jonathan West

robot said:
Hello,

I use the following code to accept all deletions in the selected area of a
document with revision marks:

Dim r As Revision
For Each r In Selection.Range.Revisions
If r.Type = wdRevisionDelete Then r.Accept
Next r

However, no matter what area I selected, the above code always accepts all
deletions in the *entire* document. What went wrong?

I use Office XP and Win XP pro. Suggestions are most welcome.

There is a bug in the Revisions collection, which I think was introduced in
Word 2002 - it is also there in Word 2003. Whatever you range you create a
Revisions collection for, the actual collection returned is the Revisions
collection for the whole document.

Therefore, you need to make an additional test in your code, whether the
revision's Range property is within the selection's range. Use the InRange
method to compare 2 ranges, or compare the Start and End properties of the
two ranges. Something like this

Dim r As Revision
For Each r In ActiveDocument.Range.Revisions
If r.Inrange(Selection.Range) Then
If r.Type = wdRevisionDelete Then
r.Accept
End If
End If
Next r


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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