Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
phosphaenus phosphaenus is offline
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
phosphaenus phosphaenus is offline
external usenet poster
 
Posts: 4
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
macro produces error message Kimmie B Microsoft Word Help 11 March 14th 06 11:25 PM
Macro does not work on docs with tracked changes!! Purnima Microsoft Word Help 0 November 7th 05 08:47 AM
Macro gives wrong table count? Ed Tables 7 August 2nd 05 10:39 PM
Ideas for macro to add row for count and percentage Bradley C. Hammerstrom Tables 8 January 6th 05 10:38 AM
2000 to 2002 macro and "Could not open macro storage" Art Farrell Mailmerge 1 December 6th 04 12:40 PM


All times are GMT +1. The time now is 09:47 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"