Word.Tips.Net WordTips (Menu Interface)

Including Text Box Text in Word Counts

Word has this nifty tool that counts the number of words in your document for you. The only problem is, it doesn't count all words. For instance, if your document contains text boxes, the word count tool won't include any text in the word boxes in the overall word count for the document. This can be a real problem, particularly if you are using text boxes to implement a special document element, such as sidebars.

There is a way around the problem, however. You can count all the words in the main portion of your document as you normally would, and then write down that number. Then move the insertion point into a text box. If you run the word count tool, Word returns the number of words in that text box. If you select multiple text boxes before running the word count tool, then Word returns the count of all words in all the text boxes you selected. If you are using linked text boxes, then you don't have to select them all, but you do need to move the insertion point into the last text box in the series. When you add together the word count in the main document, plus the word count for any text boxes, you will have the word count for the entire document.

If you use text boxes a lot, the above process can get rather bothersome. If you prefer, you can create a macro that will automate the process for you. The following macro determines the word count in the main document, and adds to it the word count for each text box in the document. The result is a total word count, as described above.

Sub TxtBxCount()
    Dim i As Integer
    Dim TxtWrds As Range
    Dim TxtWrdsStats As Long
    Dim ToTxtWrds As Long
    Dim Lngwords As Long
    Dim ToWords As Long

    Lngwords = ActiveDocument.BuiltInDocumentProperties(wdPropertyWords)
    For s = 1 To ActiveDocument.Shapes.Count
        Set TxtWrds = ActiveDocument.Shapes(s).TextFrame.TextRange
        TxtWrdsStats = TxtWrds.ComputeStatistics(Statistic:=wdStatisticWords)
        ToTxtWrds = ToTxtWrds + TxtWrdsStats
    ToWords = Lngwords + ToTxtWrds
    MsgBox ("The document has " & Format(ToWords, "##,##0") & " words.")
End Sub

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1658) applies to Microsoft Word 97, 2000, 2002, and 2003.

Related Tips:

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!


Leave your own comment:

  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*What is 5+3 (To prevent automated submissions and spam.)
           Commenting Terms

Comments for this tip:

Milind Pupala    28 Jun 2016, 06:23
Dear Mr. Ken Endacott,

Thank you very much for your support.


Milind Pupala
Ken Endacott    24 Jun 2016, 06:24
The above macro will work only if there are textboxes and no other shapes. Furthermore, it does not consider textboxes that are in headers and footers, groups and canvases.

The following macro will step over shapes that do not contain text frames. It does not consider textboxes in groups and canvases as well as in other stories such as headers and footers. To include these would require additional statements that would double the size of the macro.

Sub TxtBxCount()
    Dim i As Integer
    Dim TxtWrds As Range
    Dim TxtWrdsStats As Long
    Dim ToTxtWrds As Long
    Dim Lngwords As Long
    Dim ToWords As Long
    Dim TxtFrame As TextFrame
    Dim shp As Shape
    Lngwords = ActiveDocument.BuiltInDocumentProperties(wdPropertyWords)
    For Each shp In ActiveDocument.Shapes
      If shp.Type <> msoCanvas And shp.Type <> msoLine And shp.Type <> msoGroup Then
        Set TxtFrame = Nothing
        Set TxtFrame = shp.TextFrame
        If Not TxtFrame Is Nothing Then
          Set TxtWrds = shp.TextFrame.TextRange
          TxtWrdsStats = TxtWrds.ComputeStatistics(Statistic:=wdStatisticWords)
          ToTxtWrds = ToTxtWrds + TxtWrdsStats
        End If
      End If
    Next shp
    ToWords = Lngwords + ToTxtWrds
    MsgBox ("The document has " & Format(ToWords, "##,##0") & " words.")
End Sub
Milind Pupala    24 Jun 2016, 01:34
When I tried the above macro, below error message appeared:
Run-time error '5917:
This object does not support attached text.
And when I click on Debug, below line is highlighted in yellow:
Set TxtWrds = ActiveDocument.Shapes(s).TextFrame.TextRange

Kindly help me.I am using word document created using Word 2013.
Mariano Covre    29 Apr 2016, 06:14
Hi I'm trying to run the macro but I get this msg:
Run-time error '5917:
This object does not support attached text.
Can you please help. I'm using Word 2003 and a doc that was originally created as Word 2007 and then converted to Word 2003.
Your help would be appreciated.
Thank you
Christoph    09 Nov 2012, 14:50
Dear Mr Wyatt,

Thank you VERY much for this important text area counter! As a translator I am very happy with it.

I have only one more wish, if I may say so:

Could you include an option to have the text of footnotes and endnotes counted as well, preferably with a special mention in the macro result, such as:

Main text: 100 words
Text boxes: 20 words
Footnotes: 10 words
End notes: 20 words

Would be supergreat!



Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us


Advertise with Us

Our Privacy Policy

Our Sites


Beauty and Style




DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)



Home Improvement

Money and Finances


Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives


Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2017 Sharon Parq Associates, Inc.