Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro to count tracked insertions
I've been looking for macros to count words inserted or modified, as
tracked using Track Changes. Note that I want to count inserted words and words I've changed, but not deleted words. [Ideally I could decide whether to count inserted punctuation or not, but this is a fine point for the time being] Anyway, on a Japanese newsgroup I found the following macro, posted by Miyahn (Masataka Miya****a), and it seems to work very nicely. However, for reasons I can't understand it seems to overcount by 5 or 10%, at least in my test document... I can't see any pattern to the overcounting, and if anyone can explain it (and ideally resolve it) I'd be delighted. Sub CountInsertWords() Dim aRev As Revision, I For Each aRev In ActiveDocument.Revisions If aRev.Type = wdRevisionInsert Then I = I + aRev.Range.Words.Count Next aRev MsgBox I End Sub |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro to count tracked insertions
It may require a much more complex macro to return the number of words you
expect. Using your macro, some types of tracked changes will result in a number that is higher than you may expect, for example: If a word contains more than one change, each of the changes will count (example: if the word "exitin" is changed to "exiStinG", it will count 2). Some added characters that you do not regard as a word may be regarded as a word by Word (example: a space followed by a hyphen, " -", was counted as 2 words during my test). If you want to find out how the changes in your document are counted, you could try replacing your macro by the one below while testing. The only difference is that the version below displays a message box each time one or more changed/added word strings are found. The message box shows the text string found plus the number of words (as counted by the macro). Sub CountInsertWords() Dim aRev As Revision, I For Each aRev In ActiveDocument.Revisions If aRev.Type = wdRevisionInsert Then I = I + aRev.Range.Words.Count Show message box MsgBox "Text: " & aRev.Range.Text & vbCr & _ "Words: " & aRev.Range.Words.Count End If Next aRev MsgBox I End Sub Hope this helps. -- Regards Lene Fredborg DocTools - Denmark www.thedoctools.com Document automation - add-ins, macros and templates for Microsoft Word "phosphaenus" wrote: I've been looking for macros to count words inserted or modified, as tracked using Track Changes. Note that I want to count inserted words and words I've changed, but not deleted words. [Ideally I could decide whether to count inserted punctuation or not, but this is a fine point for the time being] Anyway, on a Japanese newsgroup I found the following macro, posted by Miyahn (Masataka Miya****a), and it seems to work very nicely. However, for reasons I can't understand it seems to overcount by 5 or 10%, at least in my test document... I can't see any pattern to the overcounting, and if anyone can explain it (and ideally resolve it) I'd be delighted. Sub CountInsertWords() Dim aRev As Revision, I For Each aRev In ActiveDocument.Revisions If aRev.Type = wdRevisionInsert Then I = I + aRev.Range.Words.Count Next aRev MsgBox I End Sub |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro to count tracked insertions
The biggest problem with the original macro is that the Words
collection counts many kinds of punctuation marks (periods, question marks, etc.) and each paragraph mark as a separate "word". Any of those items that occur within tracked inserts will inflate the count reported by the macro. An alternative that doesn't have that drawback is to use the built-in Tools WordCount dialog. Calling .Execute on the dialog object lets it count the number of words (and characters, sentences, etc.) in the Selection without actually displaying the dialog. The drawback is that it requires each insertion to be selected while the dialog is invoked, so it takes a little extra machinery in the macro. Here's my variant: Sub CountInsertWords2() Dim aRev As Revision, I As Integer, rgOrig As Range Set rgOrig = Selection.Range Application.ScreenUpdating = False For Each aRev In ActiveDocument.Revisions If aRev.Type = wdRevisionInsert Then aRev.Range.Select With Dialogs(wdDialogToolsWordCount) .Execute I = I + .Words End With End If Next aRev rgOrig.Select Application.ScreenUpdating = True MsgBox I & " words" Set rgOrig = Nothing End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. On Thu, 1 Feb 2007 15:11:00 -0800, Lene Fredborg wrote: It may require a much more complex macro to return the number of words you expect. Using your macro, some types of tracked changes will result in a number that is higher than you may expect, for example: If a word contains more than one change, each of the changes will count (example: if the word "exitin" is changed to "exiStinG", it will count 2). Some added characters that you do not regard as a word may be regarded as a word by Word (example: a space followed by a hyphen, " -", was counted as 2 words during my test). If you want to find out how the changes in your document are counted, you could try replacing your macro by the one below while testing. The only difference is that the version below displays a message box each time one or more changed/added word strings are found. The message box shows the text string found plus the number of words (as counted by the macro). Sub CountInsertWords() Dim aRev As Revision, I For Each aRev In ActiveDocument.Revisions If aRev.Type = wdRevisionInsert Then I = I + aRev.Range.Words.Count ’Show message box MsgBox "Text: " & aRev.Range.Text & vbCr & _ "Words: " & aRev.Range.Words.Count End If Next aRev MsgBox I End Sub Hope this helps. |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro to count tracked insertions
Very many thanks. I'm aware this is professional advice from
professional specialists: a rare privilege indeed. I'll look into your very pertinent suggestions. Thank you once more. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
macro produces error message | Microsoft Word Help | |||
Macro does not work on docs with tracked changes!! | Microsoft Word Help | |||
Macro gives wrong table count? | Tables | |||
Ideas for macro to add row for count and percentage | Tables | |||
2000 to 2002 macro and "Could not open macro storage" | Mailmerge |