Including Text Box Text in Word Counts

by Allen Wyatt
(last updated October 19, 2015)

5

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
    Next
    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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Retaining Explicit Formatting after Applying Styles

The formatting in a document is often a mix of styles and explicit formatting, applied over time. You may want to apply ...

Discover More

Viewing Files of a Certain Type

When you choose to open a file, Word normally displays only those files that end with the .DOC extension. If you want to ...

Discover More

Shortening ZIP Codes

US ZIP Codes can be of two varieties: five-digits or nine-digits. Here's how to convert longer ZIP Codes to the shorter ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (menu)

No-border Text Boxes by Default

Text boxes can be a great design element when laying out your documents. If you want those text boxes to have no borders (or ...

Discover More

Inserting a Text Box

Text boxes are a great way to implement non-standard ways of laying out your document. They allow you to put text at ...

Discover More

Selecting Text in Linked Text Boxes

Text boxes are often used as design elements in a document layout. If you have linked text boxes, you may have noticed that ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 + 0?

2016-06-28 06:23:08

Milind Pupala

Dear Mr. Ken Endacott,

Thank you very much for your support.

Regards,

Milind Pupala


2016-06-24 06:24:27

Ken Endacott

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


2016-06-24 01:34:48

Milind Pupala

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.


2016-04-29 06:14:31

Mariano Covre

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


2012-11-09 14:50:28

Christoph

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!

TIA!

Christoph


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.