Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Intelligent Title Case.
Written by Allen Wyatt (last updated January 20, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021
Word allows you to adjust the case of selected text. Display the Home tab of the ribbon and then clicking the Change Case tool (Aa) in the Font group. You'll see a list of different ways in which Word 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 some of the words in the text should not be capitalized. The rules can be tricky, however, which is why Word probably doesn't try to make a determination as to what should be uppercase and what shouldn't—it's easier to just make them all uppercase.
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 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 contents of sTest are 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:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (3868) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, Word in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Word here: Intelligent Title Case.
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!
Word allows you to change the character of how your pages are designed by using multiple sections in a document. If you ...
Discover MoreDo you need to add a line to your document that indicates where a signature should be made? If you don't want that line ...
Discover MoreWord allows you to apply protection to your documents that can affect which tools users can access. If you want to exempt ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-01-29 02:11:15
Len Barrows
I found this to be a useful macro but recently I wanted to change text in a table. Unfortunately, this doesn't seem to work!
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments