Consulting

Results 1 to 4 of 4

Thread: Excluding punctuation characters from tracked changes counts

  1. #1
    VBAX Newbie
    Joined
    Jul 2021
    Posts
    2
    Location

    Post Excluding punctuation characters from tracked changes counts

    Hi all,


    I have been working with the below macro for some time. The macro calculates the number of words inserted and deleted when using tracked changes. However, in the last few days, I've noticed that it was quite over-sensitive and recognise punctuation characters too, whereas I'm looking to count just whole words. I've tried to amend the coding, but I'm non-the-wiser. Would anyone have any words of advice?


    Sub GetTCStats()
    '
    ' GetTCStats Macro
    
    
    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

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,704
    Location
    What does this return?
    For Each oRevision In ActiveDocument.Revisions
       x = oRevision.Range
    Press F2 in VBA to browse all objects and their properteies.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Newbie
    Joined
    Jul 2021
    Posts
    2
    Location
    Thanks SamT. I did that. Is this what you were guiding me to?

    Screenshot 2021-07-05 082845.jpg

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,704
    Location
    I think I am pretty good with VBA, but I really don't know Word. I'm just trying to give some VBA hints, you will have to work out what works,
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •