Word.Tips.Net WordTips (Menu Interface)

Intelligent Title Case

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.

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.

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 4+5 (To prevent automated submissions and spam.)
          Commenting Terms

Comments for this tip:

Ken Endacott    04 Oct 2015, 05:10
The following macro will give intelligent title case to the sentence and show as revisions only those characters that have changed.

Sub TitleCase2()
Dim lclist As String
Dim j As Integer
Dim k As Integer
Dim sTest As String
Dim ww As Range
Dim SentRange As Range
Dim HighlightRevisions As Boolean

' highlighting of revisions must be off
HighlightRevisions = ActiveDocument.ShowRevisions
ActiveDocument.ShowRevisions = False

' list of lowercase words, surrounded by spaces
lclist = " of the by to this is from a an or but and on in with under near upon at be are it "

Set SentRange = Selection.Range
For Each ww In SentRange.Words
j = 2
Do While j <= Len(ww.Text)
Call ChangeCharCase(ww, j, False)
j = j + 1
sTest = " " & LCase(Trim(ww.Text)) & " "
If InStr(lclist, sTest) = 0 Or ww.Start = SentRange.Start Then
Call ChangeCharCase(ww, 1, True)
Call ChangeCharCase(ww, 1, False)
End If
Next ww
' restore highlighting of revisions
ActiveDocument.ShowRevisions = HighlightRevisions
End Sub

Sub ChangeCharCase(ww As Range, j As Integer, UPcase As Boolean)
Dim Ch As String
Dim Cc As String
Ch = Mid(ww, j, 1)
If UPcase Then
Cc = UCase(Ch)
Cc = LCase(Ch)
End If
If Ch <> Cc Then
Selection.MoveRight Unit:=wdCharacter, Count:=-1
Selection.TypeText Cc
Selection.Delete Unit:=wdCharacter, Count:=1
End If
End Sub
Ken Endacott    19 Sep 2015, 16:19
I have a macro to give intelligent title case that will show changes as revisions. However the submission software will not allow me to post it.
Ken Endacott    19 Sep 2015, 07:33
The case change functions in Word do not show as revisions in Track Changes. When editing documents it is often desirable to show when capitalisation has changed.

Patrick R    17 Sep 2015, 12:20
This is great!

But line 6 needs a lot of additions, for this to be useful. I'm sure there are grammatical lists somewhere which could be referenced? In the mean time, I used

lclist = " of the by to this is from a an or but and on in with under near upon at be are is"
Kenneth    03 Mar 2015, 12:35
This is great - but is there a way to have this work when multiple (non-contiguous) lines of text are selected? I would like to use this as follows: select a heading, then use 'select text with similar formatting', then apply the macro. The macro does not presently apply to all selected lines under these circumstances.
Eoin    05 Nov 2014, 06:50
I'd like to know if there's a way to apply this macro automatically to headings only.
Linda S    04 May 2014, 12:56
Thanks for sharing this macro. I changed the word list to conform with Chicago Manual of Style rules. Works like a charm!
Carl Witthoft    10 Sep 2013, 15:40
Just saying thanks -- saved me the trouble of hashing out this macro.
In response to Steve Dunham: OK, that's why each of us can write our own 'lclist' of words.
Steve Dunham    15 Jul 2013, 08:17
Actually, the standard rule is to capitalize all nouns, verbs, adjectives and adverbs, no matter what their length. "Is" is a verb and ought to be capitalized even though it's only two letters long.
Thierry Hoornaert    13 Jul 2013, 18:58
To make it really intelligent, what about a language dependent version:
Sub TitleCase()
    Dim lclist As String
    Dim wrd As Integer
    Dim sTest As String

    ' list of lowercase words, surrounded by spaces
    ' made language dependent
    Select Case Selection.LanguageID
        Case wdBelgianFrench, wdFrench
            lclist = " le la les du de par à au aux pour "
        Case wdBelgianDutch, wdDutch
            lclist = " de het van voor dit deze die "
        Case Else
            lclist = " of the by to this is from a an for "
    End Select
    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

I've looked for a Word command to replace the TitleCase function with this code, but I didn't find it.

Many thanks for your tips.
M Wilson    13 Jul 2013, 17:38
Although not the real point of the above Tip, one of the shortcuts I use the most in Word is to toggle between all Change Case options on selected text by pressing Shift+F3 repeatedly.


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