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: Intelligent Title Case.

Intelligent Title Case

Written by Allen Wyatt (last updated February 22, 2020)
This tip applies to Word 97, 2000, 2002, and 2003


5

Word contains a couple of different ways that you can adjust the case of selected text. One way is to click Format | Change Case to display the Change Case dialog box. Word lists different ways in which it can adjust the case of your text. One of the most common case changes is title case. This type of change results in each word of the selected text being uppercase, while the rest of the letters are in lowercase. The only problem with this is that Word is rather indiscriminate in what it capitalizes. For instance, if you select the text "this is a test" and then use the Change Case dialog box to change the text to title case, you end up with "This Is A Test." Common rules of capitalization, however, would dictate that the "short" words ("is" and "a") should not be capitalized.

This is where a macro comes in handy. You can create a macro to intelligently apply title case to a text selection. The macro can be programmed so that it ignores a specific set of words while doing its work. Consider the following macro:

Sub TitleCase()
    Dim lclist As String
    Dim wrd As Integer
    Dim sTest As String

    ' list of lowercase words, surrounded by spaces
    lclist = " of the by to this is from a "

    Selection.Range.Case = wdTitleWord

    For wrd = 2 To Selection.Range.Words.Count
        sTest = Trim(Selection.Range.Words(wrd))
        sTest = " " & LCase(sTest) & " "
        If InStr(lclist, sTest) Then
            Selection.Range.Words(wrd).Case = wdLowerCase
        End If
    Next wrd
End Sub

When you select some text and run this macro, the first thing it does is to change the text to Word's standard title case. It then steps through the words in the selection (Word makes the words available in the Words collection), examining each one. Each word is extracted and placed in the sTest variable, which then is converted to lowercase. The content of sTest is then checked against the lclist string to see if there is a match. If there is, then the word in the original text is converted to lowercase.

The key to the macro is the lclist string. This string contains a list of words that you want to always appear in lowercase. These words are surrounded by spaces—including the first and last words of the string. When the sTest comparison is done, sTest contains a leading and trailing space so that successful matches can be made. (The spaces are included so that there are no mistakes in word matching, for instance matching "he" to a part of "the".)

Note, as well, that the comparison portion of the macro doesn't pay attention to the first word in the text selection. This word is assumed to be the first word of a phrase or sentence, which should always start with an uppercase character.

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 (215) 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: Intelligent Title Case.

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

Noting Table Rows Containing a Character

If you want to have Word highlight rows in a table that contain a certain character, you need to resort to using a macro. ...

Discover More

Rounded Corners on Cells

As you are formatting a worksheet, Excel allows you to easily add borders to cells. Adding rounded corners to cells is a ...

Discover More

Signing a Protected Form

Tablet PCs are great for some uses, such as signing forms developed in Word. You may run into a problem with getting the ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (menu)

Resetting Default Character Formatting

If you need to remove any explicit character formatting from some text, you'll want to commit the shortcut in this tip to ...

Discover More

Embossing Text

Word can make your text look as if it has been embossed on the page.

Discover More

Quickly Increasing Point Size

Want to adjust the size of a text selection? Here's a quick shortcut to increase the size.

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?

2023-06-13 15:51:46

Connie

I love this macro, but I noticed today that it doesn't work when I run it on text in a table cell. For some reason, the value of Selection.Range.Words.Count is returned as 1 no matter how many words are in the selection range. However, if I take the text string out of the table, the macro works correctly. Anyone know why that would be or how to fix it?


2021-01-29 01:54:47

Lee Quinn

Thanks Ken, appreciate it! I'm still learning :)


2021-01-28 05:47:35

Ken Endacott

Lee,

Your macro goes into an endless loop if Track Changes and Show Markup are on. This could be avoided by inserting after the Dim statements:

ActiveDocument.TrackRevisions = False
ActiveWindow.View.ShowRevisionsAndComments = False

Editor’s clients often specify that any changes be highlighted using Track Changes. Neither Allen’s or Lee’s macros will do that.


2021-01-27 20:13:34

Lee Quinn

for what it's worth, here's my take - thanks to Allen for the inspiration :)

Private Sub Tools_Set_Heading_Title_Case()
'
' affects ALL document content
'
' set expected 'proper' case for each heading
' find and set upper case where required
' find and set lower case where required
' reapply style to heading in case someone originally created the style as 'all caps'/'small caps'
' as we still want to see the 'proper' case in the navigation pane
'
' https://word.tips.net/T000215_Intelligent_Title_Case.html
' https://cybertext.wordpress.com/2011/07/01/word-macro-to-change-headings-to-sentence-case/
'
Dim objStyle As Style
Dim arrTargetStyles(), arrTargetAllUpperCaseWords(), arrTargetAllLowerCaseWords()
Dim varCounter As Variant, arrUWord As Variant, arrLWord As Variant

arrTargetStyles = Array("Heading 1", "Heading 2", "Heading 3", "Heading 4")
arrTargetAllUpperCaseWords = Array("AS ", "CBTS", "CF", "CPU", "HMI", "HSTS", "LDS", "NTP", "PLC", "RCA", "RS LDS", "RS-LDS", "SD", "VSS", "WMS")
arrTargetAllLowerCaseWords = Array(" and ", " for ", " of ", " on ", " the ", " to ")

For Each varCounter In arrTargetStyles
With Selection.Find
.ClearFormatting
.Wrap = wdFindContinue
.Forward = True
.Format = True
.MatchWildcards = False
.Text = ""
.Style = ActiveDocument.Styles(varCounter)
.Execute

While .found
'Selection.Select
'Debug.Print "Configuring "; varCounter; " "; Selection.Text
' set title case
Selection.Range.Case = wdTitleWord
' find and fix upper case matching words
For Each arrUWord In arrTargetAllUpperCaseWords
If InStr(1, Selection.Text, arrUWord, vbTextCompare) > 0 Then
Selection.Text = Replace(Selection.Text, arrUWord, UCase(arrUWord), 1, 1, vbTextCompare)
End If
Next arrUWord
' find and fix lower case matching words
For Each arrLWord In arrTargetAllLowerCaseWords
If InStr(1, Selection.Text, arrLWord, vbTextCompare) > 0 Then
Selection.Text = Replace(Selection.Text, arrLWord, LCase(arrLWord), 1, 1, vbTextCompare)
End If
Next arrLWord
' reapply style to heading
Selection.Style = varCounter
Selection.Collapse Direction:=wdCollapseEnd
.Execute
Wend
End With
Next varCounter

Set objStyle = Nothing
Set varCounter = Nothing
Erase arrTargetStyles
Erase arrTargetAllUpperCaseWords
Erase arrTargetAllLowerCaseWords

Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst

'Debug.Print "Finished!"
End Sub


2020-05-25 13:27:44

Jim Dandy

I'm trying to do this for PowerPoint but I can only find a way to apply title case to slide titles. I cannot seem to figure out the proper way to title-case selected text like that which exists in the text boxes and content sections.


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.