a Macro for Word that counts Track Changes yields errors :(

Status
Not open for further replies.

ariellata

New member
Joined
Dec 19, 2019
Messages
1
Programming Experience
Beginner
Hi Everyone,

I need help in VB since I am not a coder.

Translation professionals around the world pass on to each other a Word Macro called GetTCStats in order to count insertions and deletions made in a Word document with Track Changes.

In some documents, it does not work at all, and it yields "Requested object is not available" (Run-time error '5852') and when I open debugging it highlights the line "Select Case oRevision.Type"

In other documents I tested, it worked fine, and there's no error, but when I "step into" and hover the "Select Case" line, I see it has an "oRevision.Type = <Object variable or With block variable not set>" comment.

Is the object not set correctly? Can anyone help solve this issue?

Very grateful for any help,

ariellata

note: if I did not post according to posting guidelines, my apologies, I am new to this.

Macro:

Sub GetTCStats()
Dim lInsertsWords As Long
Dim lInsertsChar As Long
Dim lDeletesWords As Long
Dim lDeletesChar As Long
Dim sTemp As String
Dim oRevision As Revision
lInsertsWords = 0
lInsertsChar = 0
lDeletesWords = 0
lDeletesChar = 0
For Each oRevision In ActiveDocument.Revisions
Select Case oRevision.Type
Case wdRevisionInsert
lInsertsChar = lInsertsChar + Len(oRevision.Range.Text)
lInsertsWords = lInsertsWords + oRevision.Range.Words.Count
Case wdRevisionDelete
lDeletesChar = lDeletesChar + Len(oRevision.Range.Text)
lDeletesWords = lDeletesWords + oRevision.Range.Words.Count
End Select
Next oRevision
sTemp = "Insertions" & vbCrLf
sTemp = sTemp & " Words: " & lInsertsWords & vbCrLf
sTemp = sTemp & " Characters: " & lInsertsChar & vbCrLf
sTemp = sTemp & "Deletions" & vbCrLf
sTemp = sTemp & " Words: " & lDeletesWords & vbCrLf
sTemp = sTemp & " Characters: " & lDeletesChar & vbCrLf
MsgBox sTemp
End Sub
 

Attachments

  • GetTCStats.txt
    1.1 KB · Views: 22
  • Image 1039.jpg
    Image 1039.jpg
    309.8 KB · Views: 20
  • Image 1038.jpg
    Image 1038.jpg
    68.7 KB · Views: 25
Macros for Word and other Office products are written in VBA, which is a different language to VB.NET, even though the syntaxes are closely related. I'm afraid that this is npt a valid question for this site.
 
Status
Not open for further replies.

Latest posts

Back
Top