Track changes in word 2003 problem

D

Doug Claar

I am trying to go through the changes in a document, and only accept the ones
before a certain date. (Someone forgot to accept all the changes before
continuing on, so now the document has all the changes from forever).

I tried this:

Dim output As String
Dim k As Integer
k = 0
For i = 1 To ActiveDocument.Revisions.Count
' For i = 1 To 5
With ActiveDocument.Revisions.Item(i)
If .Date < #5/26/2005# Then
output = output & .Author & " " & .Date & Chr(13)
.Accept

k = k + 1
End If

End With
Next
MsgBox (output)

But after about 30 changes, the Item comes up as "deleted": Not deleted as in
"this text was deleted", deleted as in "this variable has no content"! I
modified my script to not do the Accept, thinking that Accepting one revision
might make others go away, but nothing changed. So I added some code to ignore
deleted ones. Of the 1550 items found by Count, only about 50 were *not*
deleted! And after the script ran, revisions that were before the date were
still showing up in the document.

So I tried:

Dim output As String
Dim k As Integer
k = 0
ActiveDocument.SelectAllEditableRanges
Do While True
Set revTemp = Selection.NextRevision(Wrap:=False)
If Not (revTemp Is Nothing) Then
If .Date < #5/26/2005# Then
output = output & .Author & " " & .Date & Chr(13)
' .Accept
k = k + 1
End If
End If
MsgBox (output)
Loop


But this ran forever! (Well, over 5000 times when I killed it. BTW, is there
any way to interrupt a macro without killing the whole thing in the task
manager? I put in a MsgBox to stop every 500, but that was a pain).

Interestingly, when I capture a macro of going to the next change and
accepting it, the macro uses WordBasic stuff that isn't defined in the VB
help, like:

WordBasic.nextchangeorcomment
Selection.Range.Revisions.AcceptAll
WordBasic.AcceptChangesSelected

Anyone have any thoughts on how to make this work right?

==Doug Claar
 
J

Jezebel

The problem with the first version is this: When you start a For ... Next
loop, VB calculates the start and end values. These calculations are
performed only once, not re-evaluated with each pass. So in this case,
although deleting or accepting revisions reduces Revisions.Count, the loop
will iterate for the number of revisions you started with. Thus your index
is overrunning the collection.

Try it like this --

Dim pRevision as Word.Revision

For each pRevision in ActiveDocument.Revisions
with pRevision
if .Date ....

end with
Next
 
B

Barry Schwarz

I am trying to go through the changes in a document, and only accept the ones
before a certain date. (Someone forgot to accept all the changes before
continuing on, so now the document has all the changes from forever).

I tried this:

Dim output As String
Dim k As Integer
k = 0
For i = 1 To ActiveDocument.Revisions.Count

If you loop backwards from .Count to 1 you will avoid the problems
caused by the .Accept below.
' For i = 1 To 5
With ActiveDocument.Revisions.Item(i)
If .Date < #5/26/2005# Then
output = output & .Author & " " & .Date & Chr(13)
.Accept

k = k + 1
End If

End With
Next
MsgBox (output)

But after about 30 changes, the Item comes up as "deleted": Not deleted as in
"this text was deleted", deleted as in "this variable has no content"! I
modified my script to not do the Accept, thinking that Accepting one revision
might make others go away, but nothing changed. So I added some code to ignore
deleted ones. Of the 1550 items found by Count, only about 50 were *not*
deleted! And after the script ran, revisions that were before the date were
still showing up in the document.

So I tried:

Dim output As String
Dim k As Integer
k = 0
ActiveDocument.SelectAllEditableRanges
Do While True
Set revTemp = Selection.NextRevision(Wrap:=False)
If Not (revTemp Is Nothing) Then
If .Date < #5/26/2005# Then
output = output & .Author & " " & .Date & Chr(13)
' .Accept
k = k + 1
End If
End If
MsgBox (output)
Loop


But this ran forever! (Well, over 5000 times when I killed it. BTW, is there
any way to interrupt a macro without killing the whole thing in the task
manager? I put in a MsgBox to stop every 500, but that was a pain).

Interestingly, when I capture a macro of going to the next change and
accepting it, the macro uses WordBasic stuff that isn't defined in the VB
help, like:

WordBasic.nextchangeorcomment
Selection.Range.Revisions.AcceptAll
WordBasic.AcceptChangesSelected

Anyone have any thoughts on how to make this work right?

==Doug Claar



<<Remove the del for email>>
 
D

Doug Claar

Oops! Spoke, err--wrote--too soon. If I go into the VB editor with my document
right after I open it, having done *nothing* to it, and I set a watch on
ActiveDocument.Revisions, it tells me that Count=510. But if I expand, say,
Item 12, it tells me that the item has been deleted! So apparently, this is a
condition going into the macro, not one caused by the macro's execution. Sigh.

If I do something simple like:

Dim k as Integer
k = 0
Dim pRevision as Word.Revision
For Each pRevision In ActiveDocument.Revisions
If Not (pRevision Is Nothing) Then
k = k + 1
End If
Next

And I run it, it dies with an integer overflow in k (k > 32767).

I'm not going to spend any more time on this, but I thought I'd report back
that the solutions indicated didn't work. BTW, I'm running Microsoft Office
Word 2003 (11.6502.6408) SP1, and the Office Update page says that my products
are all up-to-date.

==Doug Claar
 

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