Hi VBA gang,
A new week, a new headache. I absolutely cannot work out why I'm getting a "Run-time error '5852'. Requested object is not available" error on this one. Thought it was a simple code, but no! The debugger seems to flip out on the select case part of the code. Any ideas why this simple code isn't working? All I'm trying to do is count tracked insertions and deletions.
Sub InDel_Counter()
Dim rvcnt, rvcnt2, a As Long
Dim oRevision As Revision
rvcnt = ActiveDocument.Revisions.Count
rvcnt2 = 0
For Each oRevision In ActiveDocument.Revisions
Select Case oRevision.Type
Case wdRevisionInsert, wdRevisionDelete
With oRevision
If .Type = wdRevisionInsert Or wdRevisionDelete Then rvcnt2 = rvcnt2 + 1
End With
End Select
Next oRevision
MsgBox "There are " & rvcnt2 & " tracked insertions and deletions.", vbOKOnly
End Sub
*Updated to add:*
I've even tried a much more convoluted way, but to no avail:
Sub InDel_Counter()
Dim rvcnt, rvcnt2, a As Long
Dim oRevision As Revision
Dim tDoc As Document
Set tDoc = ActiveDocument
rvcnt = tDoc.Revisions.Count
rvcnt2 = 0
For Each oRevision In tDoc.Revisions
If oRevision.Type = wdRevisionConflict Or wdNoRevision Or wdRevisionCellDeletion Or wdRevisionCellInsertion Or wdRevisionCellMerge _
Or wdRevisionCellSplit Or wdRevisionConflict Or wdRevisionConflictDelete Or wdRevisionConflictInsert Or wdRevisionDisplayField _
Or wdRevisionMovedFrom Or wdRevisionMovedTo Or wdRevisionParagraphNumber Or wdRevisionParagraphProperty Or wdRevisionProperty _
Or wdRevisionReconcile Or wdRevisionReplace Or wdRevisionSectionProperty Or wdRevisionStyle Or wdRevisionStyleDefinition _
Or wdRevisionTableProperty Then
GoTo NextoRevision
ElseIf oRevision.Type = wdRevisionDelete Or wdRevisionInsert Then
rvcnt2 = rvcnt2 + 1
Else
GoTo NextoRevision
End If
NextoRevision:
Next
MsgBox "There are " & rvcnt2 & " tracked insertions and deletions.", vbOKOnly
End Sub