locked
Incorrect Word Count Word 2007 RRS feed

  • Question

  • We're a Windows 7 shop running Office Enterprise 2007 SP2 - Word 2007 (12.0.6545.5000) SP2 MSO (12.0.6535.5002)

    Just recently we've noticed that the word count is incorrect in a number of Word documents.  As it stands, the contents of the headers & footers are not being included in the count, regardless of the status of the 'Include textboxes, footnotes and endnotes' checkbox, and it doesn't seem to matter whether or not it was an existing document or a brand new document.

    I went through a quick round of testing this evening & charted the results.  We use a Document Management System (DMS) that adds the current document number into the footer once its been saved.  Knowing this, I expected a new blank document, that has no text in it, to show up with '1' once its been saved into the DMS.  Unfortunately, that wasn't the case - the count remained at zero.  The same was also true for new documents with text (generated via random text) and new documents generated via [third party] templates.

    Document Type

    Saved

    Checked/Unchecked

    Count

    Correct Count

    Notes

    New Blank

    No

    Checked

    0

    Appears to be

    New Blank

    Yes

    Checked

    0

    No: 1

    Footer now has doc number, is not included in count.  If I step into the header/footer view it does not update the count nor does it simply count the contents of the footer.

    If I highlight the document number, it only counts what’s highlighted.  Once deselected, it goes back to the count of 0 instead of 1.

    Doesn’t matter if 'Include textboxes, footnotes and endnotes' box is checked or unchecked, or whether or not I’m in the header or footer view.

    New =rand(1,1)

    No

    Checked

    20

    Appears to be

    New =rand(1,1)

    Yes

    Checked

    20

    No: 21

    Same as above

    Payne>Agreement

    No

    Unchecked

    55

    No: Should be near 70

    As above, footer contents not counted

    Payne>Agreement

    Yes

    Unchecked

    55

    No: Should be near 70

    Same as above

    Payne>CA USDC Pleading

    No

    Unchecked

    19

    Appears to be

    Payne>CA USDC Pleading

    Yes

    Unchecked

    19

    No: 20

    Same as above

    In some cases there was text in the header & footer, so I removed chunks of text in the header & the counts never changed.  The same is also true for the footer.

    At one point I was wondering if the issue was caused by the presence of fields in the header/footers or document itself.  In the case of the new blank & new random documents above, once the document is saved, the footer contains the document number which is in actuality a field & not straight text.  As mentioned, highlighting the field, or the field + regular text, correctly counts the selection, but once de-selected the count is incorrect.  I retyped the document number in the footer, checked the count: no change; Then removed the field & rechecked the count but again no change.

    Its almost as if the 'Include textboxes, footnotes and endnotes' feature/option isn't working or that Word isn't registering it as checked or unchecked.

    Has anyone else seen this?  Any ideas?


    • Edited by JuliusPIV Tuesday, April 3, 2012 9:28 PM
    Tuesday, April 3, 2012 9:25 PM

Answers

  • Hi Julius,

    I'd say the behaviour is by design. I think the problem is that you were reading too much into what the 'Include textboxes, footnotes and endnotes' option means.

    There's no need to try other versions - they all work the same way.

    The following macro generates a comprehensive set of word counts for a document. If you only want the word count for a selected range, change ‘ActiveDocument’ to ‘Selection’. Do note that, with the latter, the word counts for footnotes & end notes will relate to those anchored in the selected range, regardless of where they’re physically located.

    Sub CountWords()
    Application.ScreenUpdating = False
    Dim oTbl As Table, lTbl As Long, Sctn As Section
    Dim oHdFt As HeaderFooter, lHdr As Long, lFtr As Long
    Dim oEnt As Endnote, lEnt As Long
    Dim oFnt As Footnote, lFnt As Long
    Dim oShp As Shape, lShp As Long
    Dim oPara As Paragraph, lCpt As Long
    With ActiveDocument
      For Each oTbl In .Tables
        lTbl = lTbl + oTbl.Range.ComputeStatistics(wdStatisticWords)
      Next
      For Each oEnt In .Endnotes
        lEnt = lEnt + oEnt.Range.ComputeStatistics(wdStatisticWords)
      Next
      For Each oFnt In .Footnotes
        lFnt = lFnt + oFnt.Range.ComputeStatistics(wdStatisticWords)
      Next
      For Each Sctn In .Sections
        For Each oHdFt In Sctn.Headers
          If Not oHdFt.LinkToPrevious Then _
            lHdr = lHdr + oHdFt.Range.ComputeStatistics(wdStatisticWords)
        Next
        For Each oHdFt In Sctn.Footers
          If Not oHdFt.LinkToPrevious Then _
            lFtr = lFtr + oHdFt.Range.ComputeStatistics(wdStatisticWords)
        Next
      Next
      For Each oShp In .Endnotes
        If Not oShp.TextFrame Is Nothing Then _
          lShp = lShp + oShp.TextFrame.TextRange.ComputeStatistics(wdStatisticWords)
      Next
      For Each oPara In .Paragraphs
        If oPara.Style = "Caption" Then _
          lCpt = lCpt + oPara.Range.ComputeStatistics(wdStatisticWords)
      Next
      MsgBox "Word Count Statistics:" & vbCr & _
        "Tables - " & vbTab & vbTab & lTbl & vbCr & _
        "EndNotes - " & vbTab & lEnt & vbCr & _
        "Footnotes - " & vbTab & lFnt & vbCr & _
        "Headers - " & vbTab & vbTab & lHdr & vbCr & _
        "Footers - " & vbTab & vbTab & lFtr & vbCr & _
        "Shapes - " & vbTab & vbTab & lShp & vbCr & _
        "Captions - " & vbTab & lCpt & vbCr & _
        "Other - " & vbTab & vbTab & .Range.ComputeStatistics(wdStatisticWords) - lTbl - lCpt
    End With
    Application.ScreenUpdating = True
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]


    Wednesday, April 4, 2012 9:28 PM

All replies

  • Word's word-count statistics have never purported to include header & footer content. As you have noted, there is a 'Include textboxes, footnotes and endnotes' checkbox, but you'll also note that doesn't mention headers or footers.

    There are significant issues if header & footer content is to be counted. For example, how does one handle static vs variable content? Should the header/footer on every page be counted, even if the only thing that changes is the page #? What if there's no page #? How about if a STYLEREF field is used to pull heading content from the body of the document? How should variable content related to other fields (eg a formula field that varies the output depending on the page location relative to the Section/document start/end) be handled? And, of course, each Section can have three headers & footers, each of which may or may not be linked to the content in a previous Section. How should these be handled? What about if 'same as previous' isn't checked, but the content is, in fact, the same? Once you have answers for these, just imagine what happens when consideration is given to the different answers that others might have. For every answer, what seems logical to you is unlikely to be considered so by a significant number of other Word users - even with the same organisation.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Tuesday, April 3, 2012 11:52 PM
  • Morning Paul & thanks for taking the time not only review the question but also provide an indepth response.  I won't address all your questions but you bring up interesting points.

    How does one handle static vs variable content?
    It shouldn't matter if its static of dynamic content - if the resulting code displays "My super long text" or "One-er" it should count the words.  In fact, some of our documents have several words of text [in the body] generated by field codes and Word counts those just fine.  Most fields in the header & footer are short, usually one to two words, but those, when highlighted, are counted as well.  So fields don't seem to be an issue [counting] in general. 

    Should the header/footer on every page be counted, even if the only thing that changes is the page #?
    Good question & a tricky situation for sure!  I'm not sure how the courts view page numbers: As something that is counted or not.  But then again, if we're using Word's built-in Page Numbering functionality, it should be something that could be toggled, like endnotes, textboxes etc.

    What if there's no page #?
    It doesn't count the page number, obviously, but counts everything else.

    We may be diving way too deep here because from the end user's perspective: words are words & location shouldn't matter.  If the end user can see it on screen (presumably in a normal view) it should be counted, and that's the current expectation.

    In the legal world this its very important to get an accurate word count.  Certain documents submitted to the courts must be under a specific limit.  In this case the brief must be under 14000 words, and to submit something that is say 13900 words in the body, but not counting the header & footers is not only bad form but can carry serious negative repercussions.  (I couldn't find it on Bing but I found resources supporting that here)

    I understand that there's a seemingly unlimited number of possibilities Microsoft etal would have to consider when building that functionality in, but at a minimum one would expect regular text in the top most most level of headers & footers to be counted (or whatever is currently displayed in the header/footer).  Sure it gets tricky with the inclusion of fields, but again at a minimum one would think that the resulting text within the fields (not the code itself obviously) would get counted.  It seems to handle that fine as is.  And lets not discuss different first page, sections, same as previous etc - Pandoras box!

    All this said however: I'm not here to say what Microsoft should or should not do, nor am I here to go back & forth discussing the validity of your points above, or trying to justify why it should or should not be X way.  I'm just the messenger of an end user seeking confirmation, because the expectation is that it should be counted!  So my main query:

    Is this by design or is this a bug?

    Is there a KB or some other formal document that discusses Word's exclusion of text in headers & footers in the word count?

    Is there some official documentation that covers this subject (word count) in general (including limitations, caveats, exclusions etc)?

    Is this 'fixed' in 2010? (Does 2010 behave differently than 2007 in terms of counting text?)

    As time permits I'll load up 2003 & 2010 to see if they behave the same way.



    • Edited by JuliusPIV Wednesday, April 4, 2012 3:20 PM
    Wednesday, April 4, 2012 3:11 PM
  • Neither of these pages talk about headers & footers.  By virtue of there being a lack of information on the header/footer, should we deduce that its just not possible?

    http://office.microsoft.com/en-us/word-help/count-the-number-of-words-in-a-document-HA010368775.aspx

    http://office.microsoft.com/en-us/word-help/count-the-number-of-words-in-a-document-HP005190155.aspx

    Searching 'word count' has not revealed much either.

    Wednesday, April 4, 2012 3:58 PM
  • Hi Julius,

    I'd say the behaviour is by design. I think the problem is that you were reading too much into what the 'Include textboxes, footnotes and endnotes' option means.

    There's no need to try other versions - they all work the same way.

    The following macro generates a comprehensive set of word counts for a document. If you only want the word count for a selected range, change ‘ActiveDocument’ to ‘Selection’. Do note that, with the latter, the word counts for footnotes & end notes will relate to those anchored in the selected range, regardless of where they’re physically located.

    Sub CountWords()
    Application.ScreenUpdating = False
    Dim oTbl As Table, lTbl As Long, Sctn As Section
    Dim oHdFt As HeaderFooter, lHdr As Long, lFtr As Long
    Dim oEnt As Endnote, lEnt As Long
    Dim oFnt As Footnote, lFnt As Long
    Dim oShp As Shape, lShp As Long
    Dim oPara As Paragraph, lCpt As Long
    With ActiveDocument
      For Each oTbl In .Tables
        lTbl = lTbl + oTbl.Range.ComputeStatistics(wdStatisticWords)
      Next
      For Each oEnt In .Endnotes
        lEnt = lEnt + oEnt.Range.ComputeStatistics(wdStatisticWords)
      Next
      For Each oFnt In .Footnotes
        lFnt = lFnt + oFnt.Range.ComputeStatistics(wdStatisticWords)
      Next
      For Each Sctn In .Sections
        For Each oHdFt In Sctn.Headers
          If Not oHdFt.LinkToPrevious Then _
            lHdr = lHdr + oHdFt.Range.ComputeStatistics(wdStatisticWords)
        Next
        For Each oHdFt In Sctn.Footers
          If Not oHdFt.LinkToPrevious Then _
            lFtr = lFtr + oHdFt.Range.ComputeStatistics(wdStatisticWords)
        Next
      Next
      For Each oShp In .Endnotes
        If Not oShp.TextFrame Is Nothing Then _
          lShp = lShp + oShp.TextFrame.TextRange.ComputeStatistics(wdStatisticWords)
      Next
      For Each oPara In .Paragraphs
        If oPara.Style = "Caption" Then _
          lCpt = lCpt + oPara.Range.ComputeStatistics(wdStatisticWords)
      Next
      MsgBox "Word Count Statistics:" & vbCr & _
        "Tables - " & vbTab & vbTab & lTbl & vbCr & _
        "EndNotes - " & vbTab & lEnt & vbCr & _
        "Footnotes - " & vbTab & lFnt & vbCr & _
        "Headers - " & vbTab & vbTab & lHdr & vbCr & _
        "Footers - " & vbTab & vbTab & lFtr & vbCr & _
        "Shapes - " & vbTab & vbTab & lShp & vbCr & _
        "Captions - " & vbTab & lCpt & vbCr & _
        "Other - " & vbTab & vbTab & .Range.ComputeStatistics(wdStatisticWords) - lTbl - lCpt
    End With
    Application.ScreenUpdating = True
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]


    Wednesday, April 4, 2012 9:28 PM
  • Hey Paul - Thanks for the code snippet!

    I had seen a video on counting words in a document, and some other posts elsewhere on the same subject, but didn't want to have to craft some macro to do this.  As for the toggling of the 'Include textboxes, footnotes and endnotes' option, I was curious to know whether or not that had any effect on the word count.  (read: I was wanting to confirm it did/didn't make a difference to the count.)

    Is there any official [Microsoft] documentation confirming or discussing that headers & footers aren't included in the Word count?

    Resources:

    Thursday, April 5, 2012 3:39 PM
  • check this link

    http://www.thecodecage.com/forumz/microsoft-word-forum/193310-word-2007-word-count-wrong.html

    Thursday, April 5, 2012 4:18 PM
  • Thanks for the link jigvendtechi - I ran across that in my various traverses through the search engines, but they don't let you see any of the responses unless you're a registered member, & I'm not interested in signing up.  However, if you're a member, would be great if you could copy/paste the relevant information.

    Thursday, April 5, 2012 4:48 PM
  • Hi Julius,

    That link just points to another discussion I participated in on a related issue. The OP was concerned that different word counts were being seen with different Word versions. My reply was to the effect that the difference may have been due to whether the OP had the 'Include textboxes, footnotes and endnotes' option checked. The OP seems to have accepted that, as there was no further posts.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, April 5, 2012 9:48 PM