Group: microsoft.public.word.vba.general
From: Jay Freedman
Date: Saturday, February 16, 2008 2:52 PM
Subject: Re: Replace Title Case Function with Macro?

On Sat, 16 Feb 2008 07:48:00 -0800, klam wrote:

>I use Format > Change Case > Title Case quite frequently. However, it is a
>pain to have to change all the short words (e.g., the, a, of) back to lower
>case.
>
>There is a macro that takes care of that (shown below). I was wondering if I
>should replace Word's Change Case function with this macro. Any downsides to
>doing that? I've never written my own macro before and all previous macro
>work was "step by step" instructions I followed.
>
>If I replace Word's Change Case function with this macro, can someone pls
>let me know how I would go about doing it? If I didn't replace the Word
>function, how would I set up using this macro?
>
>Using Word 2003 on standalone PC (XP).
>
>Any insights much appreciated.
>
>Here's the macro:
>Intelligent Title Case, taken from Allen Wyatt's Word Tips (on-line):
>
>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

You can intercept and replace (almost) any built-in Word command with your own
macro. The procedure is described in
http://www.word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm.

In your example, all that's necessary is to name the macro ChangeCase instead of
TitleCase.

The downside of doing this is that the Shift+F3 shortcut will no longer cycle
through the other case variations -- it will only run your macro. To get the
others, you'd have to use the menu item Format > Change Case to open the dialog.

An alternative would be to leave the macro with the name TitleCase (which
doesn't correspond to any built-in command) and instead assign it a shortcut,
menu item, and/or toolbar button of its own:
http://www.word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToHotkey.htm
http://www.word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Safety Articles | Usenet Groups | Usenet News | Bluegrass