JohnRobinAllen
asked on
VBA Word Can I find out if a document has any tracked changes?
With VBA and a Word document, I need to know if a document has any tracked changes so that I can accept or reject each change. I thought ActiveDocument.Revisions.C ount would tell me how many I have, but it does not.
A kludge is to use
On Error Resume Next
WordBasic.NextChangeOrComm ent
and if that returns an error, then I have no more changes or comments.
Surely there must be a more elegant way of solving that problem.
Thanks, as always, for the help.
j.r.a.
A kludge is to use
On Error Resume Next
WordBasic.NextChangeOrComm
and if that returns an error, then I have no more changes or comments.
Surely there must be a more elegant way of solving that problem.
Thanks, as always, for the help.
j.r.a.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The Revsions.Count should work. It does for me:
Dim rv As Revision
Debug.Print ActiveDocument.Revisions.C OUNT
For Each rv In ActiveDocument.Revisions
Debug.Print rv.Range.Text
Next rv
Dim rv As Revision
Debug.Print ActiveDocument.Revisions.C
For Each rv In ActiveDocument.Revisions
Debug.Print rv.Range.Text
Next rv
Hmm.
My WordBasic manual doesn't mention NextChangeOrComment. However, I got a 'Do you want to resume at the start of the document' message. Is that your problem message? Try selecting the whole document first.
My WordBasic manual doesn't mention NextChangeOrComment. However, I got a 'Do you want to resume at the start of the document' message. Is that your problem message? Try selecting the whole document first.
Private Function NextChangeOrComment() As Boolean
ActiveDocument.Select '<--------
On Error Resume Next
WordBasic.NextChangeOrComment
If Err.Number = 0 Then
NextChangeOrComment = True
Else
NextChangeOrComment = False
End If
End Function
ASKER
I agree with Graham that Revsions.Count should work. My problem is in a footnote, which apparently the Revision.Count ignores. The attached excerpt from a document shows a newly-added footnote. A macro named "Test" displays the Revision.Count as zero, yet there is a tracked change in the document in that added footnote. Perhaps others do not get the same result that I get.
I will temporarily use Graham's suggestion for my kludge: Application.DisplayAlerts = wdAlertsNone, but I will first leave the question open for a day or two more to see if there is not something simpler that would correct the Revision.Count and not have the computer waste its time with my NextChangeOrComment function.
j.r.a.
Test-document-with-tracked-chang.doc
I will temporarily use Graham's suggestion for my kludge: Application.DisplayAlerts = wdAlertsNone, but I will first leave the question open for a day or two more to see if there is not something simpler that would correct the Revision.Count and not have the computer waste its time with my NextChangeOrComment function.
j.r.a.
Test-document-with-tracked-chang.doc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Both Graham Skan's "CountAllRevs" and Atomsheep's supplement to my original kludge work well.
I am awarding the 300 points to Graham's 12-line complete solution, but another 100 points go to Atomsheep for his two additions to my kludge:
Application.DisplayAlerts = wdAlertsNone
Application.DisplayAlerts = wdAlertsAll
I am awarding the 300 points to Graham's 12-line complete solution, but another 100 points go to Atomsheep for his two additions to my kludge:
Application.DisplayAlerts = wdAlertsNone
Application.DisplayAlerts = wdAlertsAll
ASKER
Two solutions and each works well. Graham's solution is complete and elegant. Atomsheep's two lines make my kludge work well too.
Many thanks to both gentlemen.
j.r.a.
Many thanks to both gentlemen.
j.r.a.
ASKER
I certainly hope there is a solution out there somewhere.
j.r.a.
Open in new window