Replace Title Case Function with Macro?

K

klam

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
 
J

Jay Freedman

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
 
K

klam

Thx a mint for such a complete response, Jay! Now that I understand the
disadvantage of replacing the Word macro, I will work my way thru the links
and have it as a separate macro.

cheers,
 

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

Top