Looking for Proper Capitalization for Outlines

G

grammatim

Sorry, Word isn't that clever! The quickest way to do it is to select
your heading (title, etc.), choose Title Case in the Change Case
button, then lowercase the articles, prepositions, and conjunctions.
 
G

Graham Mayor

There is no built-in method of doing this, but you can achieve it with a
macro. One method would be to use the replace function as below. The system
uses two arrays, one of which carries the words you wish to have in lower
case but formatted with the first letter in upper case, and the second list
has the same words in the same order but all in lower case. You can add as
many or as few words as you wish (in quotes and separated by commas)
provided each has a corresponding entry in both arrays. I have filled in a
few to give you the basic idea.

Add the macro to a toolbar button or suitable keyboard shortcut -
http://www.gmayor.com/installing_macro.htm Select the text you want
formatting and it applies title case to the selected text and then replaces
the words in the list virtually instantaneously.

Sub TrueTitleCase()
Dim sText As Range
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long
Set sText = Selection.Range
If Len(sText) < 1 Then
MsgBox "Select the text first!", vbOKOnly, "No text selected"
Exit Sub
End If
sText.Case = wdTitleWord

vFindText = Array("A", "And", "But", "For", "At", "As", "The")
vReplText = Array("a", "and", "but", "for", "at", "as", "the")
With sText
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True
For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute Replace:=wdReplaceAll
Next i
End With
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

grammatim

Sorry, I don't know how to read a macro, but does it know not to
lowercase the first word ("A Tale of Two Cities") or the first word
after the colon introducing the subtitle ("Indian Epigraphy: A Guide
to the Study of Inscriptions in Sanskrit, Prakrit, and the Other Indo-
Aryan Languages") (sorry, it was the first book on my desk that has a
subtitle)?
 
G

Graham Mayor

As written it acted on the selected text without fear or favour.

The first letter issue occurred to me later and is easy enought to resolve
(see below). The second issue I hadn't considered and proved a tad more
complicated, but the following version should also address that and is
annotated. It does however only address the first colon in the string. I
have also added a couple more entries in the arrays to cater for your
specific examples.

Sub TrueTitleCaseB()
Dim sText As Range
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long
Dim k As Long
Dim m As Long
Set sText = Selection.Range
'count the characters in the selected string
k = Len(sText)
If k < 1 Then 'If none, then no string is selected
'so warn the user
MsgBox "Select the text first!", vbOKOnly, "No text selected"
Exit Sub 'and quit the macro
End If
'format the selected string as title case
sText.Case = wdTitleWord
'list the exceptions to look for in an array
vFindText = Array("A", "And", "But", "For", "At", _
"As", "The", "Of", "To", "In")
'list their replacements in a matching array
vReplText = Array("a", "and", "but", "for", "at", _
"as", "the", "of", "to", "in")
With sText
With .Find
'replace items in the first list
'with the corresponding items from the second
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True
For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute Replace:=wdReplaceAll
Next i
End With
'Reduce the range of the selected text
'to encompass only the first character
.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1
'format that character as upper case
.Case = wdUpperCase
'restore the selected text to its original length
.MoveEnd Unit:=wdCharacter, Count:=k
'and check to see if the string contains a colon
If InStr(1, sText, ":") > 0 Then
'If it does note the position of the character
'after the first colon
m = InStr(1, sText, ":") + 1
'and set that as the new start of the selected text
.MoveStart wdCharacter, m
'set the end of the selected text to include
'one extra character
.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1
'format that character as upper case
.Case = wdUpperCase
End If
End With
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

grammatim

(Per Chicago style, there should never be more than one colon in a
title. If you absolutely have to have a third component to a title,
which you shouldn't, you can set it off with a dash. Note that the
older style with "or" -- as in *Twelfth Night; or, What You Will" --
doesn;t interact with your macro.)
 
G

Graham Mayor

'or' is not included in the two arrays, but is easy to add - as would be any
other missing words, of which I am sure you could suggest a few candidates.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top