Counting Characters in Text Boxes

Written by Allen Wyatt (last updated January 26, 2021)
This tip applies to Word 97, 2000, 2002, and 2003


2

If you have a document that includes text in various text boxes, you should understand that if you do a word count, Word does not include the words in the text boxes in the word count it returns. If you want to only know the number of words in a text box, there is a way around this: Just select the text box whose words you want to count before you initiate the Word Count function. Word then dutifully counts only the words in the text box, ignoring the rest of the document.

There is one time when this select-before-count technique will not work, however. If you have multiple text boxes containing words, and those text boxes are grouped, then the Word Count function will not recognize them as "countable" if you select the group. In other words, to count the characters in the text boxes that make up the group, you must first ungroup the group and then count each text box.

Obviously, this can get tedious to do over and over again. One way around this is to use a macro that performs these same steps for you. The following macro, TextBoxCount, steps through all the shapes in your document. If they are grouped, then they are automatically ungrouped. It then executes a word count on each text box, and returns a dialog box that indicates the number of words and characters in the text boxes (collectively) and the number of words and characters in the entire document, including the text boxes.

Sub TextBoxCount()
    Dim lngTBWords As Long
    Dim lngTBChars As Long
    Dim lngDocWords As Long
    Dim lngDocChars As Long
    Dim shpTemp As Shape
    Dim wcTemp As Dialog
    Dim bDone As Boolean

    Application.ScreenUpdating = False

    Do
        bDone = True
        For Each shpTemp In ActiveDocument.Shapes
            If shpTemp.Type = msoGroup Then
                shpTemp.Ungroup
                bDone = False
            End If
        Next shpTemp
    Loop Until bDone

    'Get count in main document
    Selection.HomeKey Unit:=wdStory
    Set wcTemp = Dialogs(wdDialogToolsWordCount)
    wcTemp.Update
    wcTemp.Execute
    lngDocWords = wcTemp.Words
    lngDocChars = wcTemp.Characters

    'Step through shapes and add counts
    lngTBWords = 0
    lngTBChars = 0
    For Each shpTemp In ActiveDocument.Shapes
        shpTemp.Select
        wcTemp.Execute
        lngTBWords = lngTBWords + wcTemp.Words
        lngTBChars = lngTBChars + wcTemp.Characters
    Next shpTemp
    lngDocWords = lngDocWords + lngTBWords
    lngDocChars = lngDocChars + lngTBChars

    Application.ScreenUpdating = True
    MsgBox Str(ActiveDocument.Shapes.Count) _
      & " text boxes found with" & vbCr _
      & Str(lngTBWords) & " word(s) and" & vbCr _
      & Str(lngTBChars) & " characters" & vbCr & vbCr _
      & " In the total document there are" & vbCr _
      & Str(lngDocWords) & " word(s) and" & vbCr _
      & Str(lngDocChars) & " characters"
End Sub

Remember that this macro ungroups any grouping previously done in the document. For this reason, you may want to run the macro after saving your document, and then discard the document (reload it from disk) after getting your count.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1839) 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

Button for Leaving Full-Screen Mode

If you display your document in full-screen mode, there are a couple of ways you can get back to normal mode. One method ...

Discover More

Converting Numbers Into Words

Write out a check and you need to include the digits for the amount of the check and the value of the check written out ...

Discover More

Jumping to a Footnote

Jumping to a specific footnote can be very handy if your document has a lot of footnotes in it. Word provides the ...

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)

Equation Editor Font Color

If you want to change the color used by the Equation Editor, you may be out of luck. In fact, the best solution may be to ...

Discover More

Inserting a Sound File in Your Document

Got an audio file you want to insert in your document? It's easy to do when you use the Object dialog box, as described ...

Discover More

Refreshing the Discussion

To keep up with the Discussion, you will need to refresh the comments to make sure you are in-the-know.

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 more than 7?

2020-08-21 03:04:06

Stanley

Dear Mr Wyatt,
thank you for your suggestion to a macro-solution. However, the macro does not work. I had multiple boxes in a two-page word document, with around 200 words, but your macro counted that I should have around 160,000 words...which completely wrong. The word does not know how to count words in multiple boxes. It does the same error (giving an exorbitant number of inexisting words) each time I select with shift+click multiple boxes manually...
Thank you for your update.
Regards,


2016-11-12 16:15:22

Damian

Great tip. There are issues with the macro if you select "In Line with Text" for your wrap selection because there needs to be an anchor for this macro to recognize the text box.


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.

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