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

Hi,

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

Thanks,

OT
oaktreesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oaktreesAuthor Commented:
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! :)))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.