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

by Allen Wyatt
(last updated February 22, 2020)

4

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

Setting the Wrapping Default for Objects

Want to have objects such as text boxes and shapes always appear using some formatting you like? Here are some ideas on ...

Discover More

Applying Conditional Formatting to Multiple Worksheets

If you just updated your copy of Excel, you may have noticed some differences in how the program handles applying ...

Discover More

Converting List Types

There are two types of common lists you can create in Word: bulleted lists and numbered lists. You can switch between the ...

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)

Placing Numbers Over Other Numbers

Sometimes you need to create text that isn't as "linear" as you might expect. For instance, you may need to put some text ...

Discover More

Changing the Formatting of All Instances of a Word

Need to find all the instances of a particular word and change the formatting of those instances? It's easy to do using ...

Discover More

Making Text Bold

Want a cool shortcut to make your text bold? Here's a method that fits in wonderfully with how things are done in the ...

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}] 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 9 + 8?

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.

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.