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

Keeping Paragraphs on the Same Page

Don't want your paragraphs to flow from one page to another? Word provides a formatting setting that forces individual ...

Discover More

Deleting Index Entries

When you construct an index you need to insert all sorts of index fields throughout your document. If you want to later ...

Discover More

An Easy Way to Count Items

Need to quickly count a group of items in a document? Here's a drop-dead easy way to get that count.

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

MORE WORDTIPS (MENU)

Finding Text Boxes

Need to search for various text boxes in your document? It's easy to do with the handy macro provided in this tip.

Discover More

Wrapping Text around a Graphic in a Text Box

Word allows you to wrap text around a graphic or around a text box, but it won't allow you to wrap text in a text box around ...

Discover More

Understanding Frames and Text Boxes

What is the difference between frames and text boxes? Why use one over the other? Find out here.

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 for this tip:

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. 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 two less than 3?

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.

Links and Sharing