-
Jun 26th, 2021, 10:26 AM
#1
Thread Starter
New Member
[Word] Excluding punctuation 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, I've noticed that the count statistics are slightly different compared to the standard counts provided by Word automatically. I think the issue is that the macro below is slightly over-sensitive and counts each new item of punctuation as a separate word. I'm not sure how best to edit the macro to exclude items of punctuation from the counts. Any tips would be appreciated.
Code:
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
-
Jul 2nd, 2021, 10:23 AM
#2
Thread Starter
New Member
Re: [Word] Excluding punctuation from tracked changes counts
-
Aug 3rd, 2021, 06:43 PM
#3
Fanatic Member
Re: [Word] Excluding punctuation from tracked changes counts
https://docs.microsoft.com/en-us/off...Document.Words
Indeed white space characters and punctuations are counted as words, a workaround could be to add a 'Select case' statement into a loop (looping the words) and count everything that is not a whitespace character or a punctuation mark.
something like 'For Each' loop on the words collection then check if its in the range of characters that represent the alphabet for example. this method is probably going to take some trial and error since im not sure if a space and a punctuation mark is 1 word or 2 words, you will have to test it.
Another way might be to store the text into a string and remove everything that is not a letter or a space then run whatever method to count the words you see fit.
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|