Word.Tips.Net WordTips (Menu Interface)

Determining the Length of a String

Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Determining the Length of a String.

It is hard to imagine a function used more often with strings than the Len() function. This simple little function returns the length of any string. The following are a few examples that can work in your macros:

A = Len(MyString)
B = Len("This is a test")

The first line returns the length of the characters in the variable MyString. The second returns the number of characters between the quote marks (in this case, 14—remember that spaces count as characters).

If you want to determine the length of a selection, you follow a bit different approach:

C = Len(Selection)

This line returns the length of the current text selection in the document. Remember when calculating the length of a selection that paragraph marks (hard returns) count as two characters. That is because they are each really a carriage return followed by a line feed, even though all other macro commands treat them as a single character.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (777) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Determining the Length of a String.

Related Tips:

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!


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:

Steven Wells    24 Feb 2012, 13:58
Addendum to my previous comment:
Unlike the Len function, where a hard return counts as its two component characters, the built-in Word Count function ignores both hard and soft returns entirely, counting either as zero (0) characters.
Steve Wells    24 Feb 2012, 13:49
This tip is okay for explaining the Len function, but why bother with that approach when there is already a much better built-in function in Word, though not obviously named.

Select the text that you want to consider, and on the Tools menu, click Word Count. A small box displays the statistics for your selection:
Characters (no spaces)
Characters (with spaces)

You also can select a check box to include footnotes and endnotes.

I use this feature often, so I have placed it onto one of my toolbars. To get the toolbar button:
1. Click Tools > Customize to open the Customize dialog box.
2. In the Commands tab under Categories, click Tools.
3. In the Commands box on the right, scroll to find Word Count and drag it to your toolbar.
4. Click Close.

If you look for the command under the Category: All Commands, the same item is available (alphabetically) as ToolsWordCount, along with a couple related commands, which place a list on the toolbar rather than in a dialog box. (Personally, I find the dialog box to be the more convenient interface.)

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 © 2016 Sharon Parq Associates, Inc.