Word Macro for Shift F3-Like Auto Capitalization That Skips the Words And, But, Or, For and To

oaktrees used Ask the Experts™

In Word you can select text, hit Shift+F3, and then scroll through a variety of Auto Capitalize scenarios: All Caps, All Lower Case, All Initial Caps.

Is there any way to write a Macro that would do the Initial Caps only AND always ignore the words

and, for, to, a, of

So that, selecting the text and running the Macro on

the history of search engines and consumer response

would become

The History of Search Engines and Consumer Response

rather than

The History Of Search Engines And Consumer Response


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
This uses Find/Replace to keep listed words in lowercase
Option Explicit

Sub SetTitlecase()
    Dim strLowerWords() As String
    Dim strProperWords() As String
    Dim rng As Range
    Dim rngWord As Range
    Dim i As Integer
    'set up except words
    strLowerWords() = Split("and,for,to,a,of", ",")
    ReDim strProperWords(UBound(strLowerWords))
    For i = 0 To UBound(strLowerWords)
        strProperWords(i) = UCase(Left(strLowerWords(i), 1)) & LCase(Mid(strLowerWords(i), 2))
    Next i
    'set range to work on
    Set rng = Selection.Range
    With rng
        'capitalise first letter of every word
        .Case = wdTitleWord
        'set first letter of minor words to lower case
        For i = 0 To UBound(strLowerWords)
            With rng.Find
                .Text = strProperWords(i)
                .Replacement.Text = strLowerWords(i)
                .MatchWholeWord = True
                .MatchCase = True
                .Execute Replace:=wdReplaceAll
            End With
        Next i
    End With
    'recapitalise first letter of sentences
    rng.Case = wdTitleSentence
End Sub

Open in new window


Thanks a million!  Please keep an eye on this question.  Will try to get time to install this over the next few days.  VERY grateful! :)))

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial