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

Selecting the Entire Document with the Mouse

Want a quick way to select your entire document without taking your hand off of the mouse? Try clicking away using the ...

Discover More

Creating a Letterhead Template

Word is often used to write all sorts of letters. You may want to create a template that makes creating your letters easier ...

Discover More

Determining a Column Width

When laying out your document, you may wonder what width you should use for your text. An old typographers trick may help to ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

MORE WORDTIPS (MENU)

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

Finding an Invisible Text Box

Text boxes can be a great aid in designing the layout of your document. What do you do when you can't find a text box that ...

Discover More

Changing Orientation of a Text Box

Want to change how a text box is oriented on the page? You can't do it, but you can adjust the dimensions of the box ...

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 8 - 1?

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


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
Share