Loading
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:

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

 

Comments for this tip:

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.

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 4+5 (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2014 Sharon Parq Associates, Inc.