Intelligent Title Case

by Allen Wyatt
(last updated July 13, 2013)

17

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.

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

Replacing Characters at the End of a Cell

The Find and Replace capabilities of Excel can come in handy, but they can't accomplish all your replacement needs. One such ...

Discover More

Converting Text to Uppercase in a Macro

Macros are often used to process documents. If part of the processing involves making text selections uppercase, Word ...

Discover More

Unwanted Lines on Printout

Do you have strange lines appearing at the corners of your printout? There are a number of reasons this could be happening, ...

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)

Changing Strikethrough Lines

Want to change the way a strikethrough line appears? It's not as easy as you think, as you find out in this tip.

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

Fonts in the Font Drop-Down List

Ever wonder how to customize which fonts appear in the Font drop-down list? Making changes to this list is not easy. This tip ...

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 for this tip:

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. 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 one more than 2?

2016-04-14 10:20:32

Ken Endacott

Stacy
If (Len(sTest) = 4 Or Len(sTest) = 3 Or Len(sTest) = 2) And UCase(sTest) = sTest Then

Jennifer
It would only require minor modifications to make the macro work in PowerPoint or in Publisher.


2016-04-14 08:25:55

Stacy

Thanks So Much Ken. how would I change it if I had a four letter acro?


2016-04-13 20:46:54

Ken Endacott

Replace the statement:
j = 2

with:

sTest = Trim(ww.Text)
If (Len(sTest) = 3 Or Len(sTest) = 2) And UCase(sTest) = sTest Then
j = Len(ww.Text) + 1
Else
j = 2
End If

This will not change two or three letter all uppercase acronyms.


2016-04-12 11:52:21

stacy

so,, this message should be for ken Endicott. I am using his macro but it keeps changing all of my acronyms to lc.


2016-04-12 11:45:01

stacy

How can this be altered to leave three lettered acronyms?


2016-03-28 15:12:13

Jennifer

Is is AWESOME.
Now if someone could just make a macro like this for Powerpoint....


2015-10-04 05:10:53

Ken Endacott

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
Loop
sTest = " " & LCase(Trim(ww.Text)) & " "
If InStr(lclist, sTest) = 0 Or ww.Start = SentRange.Start Then
Call ChangeCharCase(ww, 1, True)
Else
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)
Else
Cc = LCase(Ch)
End If
If Ch <> Cc Then
ww.Characters(j).Select
Selection.MoveRight Unit:=wdCharacter, Count:=-1
Selection.TypeText Cc
Selection.Delete Unit:=wdCharacter, Count:=1
End If
End Sub


2015-09-19 16:19:34

Ken Endacott

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.


2015-09-19 07:33:07

Ken Endacott

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.


2015-09-17 12:20:17

Patrick R

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"


2015-03-03 12:35:54

Kenneth

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.


2014-11-05 06:50:14

Eoin

I'd like to know if there's a way to apply this macro automatically to headings only.


2014-05-04 12:56:51

Linda S

Thanks for sharing this macro. I changed the word list to conform with Chicago Manual of Style rules. Works like a charm!


2013-09-10 15:40:37

Carl Witthoft

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.


2013-07-15 08:17:41

Steve Dunham

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.


2013-07-13 18:58:43

Thierry Hoornaert

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.


2013-07-13 17:38:36

M Wilson

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.


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.

Links and Sharing
Share