Results 1 to 8 of 8
  1. #1
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Change Case - Title Case Problems (Word 2000 SR-3)

    Anybody know of a macro or add-in that works better than Word's built-in Chase Case - Title Case function? I get tired of fixing the capitalized "And" and "Of" when I use Title Case.

    Thx.

    -Rich Belthoff

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change Case - Title Case Problems (Word 2000 SR-3)

    Hi Rich:
    I don't, but if you find one, please post back. It was definitely the "easy way out" to capitalize every word with Title Case. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Change Case - Title Case Problems (Word 2000 SR-3)

    Here's something I just came up with. I'll be interested to see what you decide to put in the list (line in red below):
    <pre>Sub TestSmartInitialCap()
    MsgBox SmartInitialCap("this is a brief sample for testing " & _
    "the smart initial capping function.")
    End Sub

    Function SmartInitialCap(ByVal strOriginal As String) As String
    ' Returns a string where all but selected words are initial capped
    If Len(Trim(strOriginal)) = 0 Then
    ' Set return to "blank" input string
    SmartInitialCap = strOriginal
    Exit Function
    End If
    ' Divide strOriginal into an array of words
    Dim strArray() As String, intCounter As Integer
    strArray = Split(strOriginal, " ")
    ' Set up | delimited list of "not capped" words
    Dim strNotCapped As String
    <font color=red>strNotCapped = "|a|an|the|and|or|of|in|on|for|"</font color=red>
    ' Loop through all the words and try to initial cap in a smart way
    For intCounter = 0 To UBound(strArray)
    If StrComp(strArray(intCounter), _
    StrConv(strArray(intCounter), vbUpperCase), _
    vbBinaryCompare) = 0 Then
    ' It's all upper case or not alphabetic
    ' Make no change to this array element
    Else
    ' Alway initial cap the first word; initial cap the others if
    ' they cannot be found in the "not capped" list
    If (intCounter = 0) Or (InStr(1, strNotCapped, _
    "|" & strArray(intCounter) & "|", vbTextCompare) = 0) Then
    strArray(intCounter) = StrConv(strArray(intCounter), vbProperCase)
    End If
    End If
    Next
    SmartInitialCap = Join(strArray, " ")
    End Function</pre>

    Note that the Split() and Join() methods were added to VBA in version 6, Office 2000. Apologies to Office 97 fans.

  4. #4
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Change Case - Title Case Problems (Word 2000 SR-3)

    Sorry for the delay in replying, but I actually had to get some real work done before playing with this. <grin> Anyway, this works great! I am not yet sure what words I might include in the list, although I might include "is" and "to" in the list (although "to" is supposed to be capitalized if it marks an infinitive (ok, I don't really know what that means, but I read it on a web site! <grin>)). Anyway, I modified the code so that it'll work with the current selection, and here's what I came up with:

    Sub TestSmartInitialCap()
    Dim vTextString As String, vCapString As String
    If Selection.Type <> wdSelectionIP Then
    vTextString = Selection.Text
    vCapString = SmartInitialCap(vTextString)
    Selection.TypeText Text:=vCapString
    End If
    End Sub

    Thx.

    -Rich Belthoff

  5. #5
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Change Case - Title Case Problems (Word 2000 SR-3)

    By the way, in my test, I hate an all-caps word, and the macro didn't change it, but I guess that's a problem with Word, because Word didn't change it either when I just used the change case function. I suppose I could force everything to lowercase first in the macro, and then run your code on the selection.

    Thx.

    -Rich Belthoff

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Change Case - Title Case Problems (Word 2000 SR-3)

    My code intentionally leaves all CAPS words because I figured they probably were acronyms. If you want to change that, you can simplify this part of the code -
    <pre>For intCounter = 0 To UBound(strArray)
    If StrComp(strArray(intCounter), _
    StrConv(strArray(intCounter), vbUpperCase), _
    vbBinaryCompare) = 0 Then
    ' It's all upper case or not alphabetic
    ' Make no change to this array element
    Else
    ' Alway initial cap the first word; initial cap the others if
    ' they cannot be found in the "not capped" list
    If (intCounter = 0) Or (InStr(1, strNotCapped, _
    "|" & strArray(intCounter) & "|", vbTextCompare) = 0) Then
    strArray(intCounter) = StrConv(strArray(intCounter), vbProperCase)
    End If
    End If
    Next</pre>

    - to this:
    <pre>For intCounter = 0 To UBound(strArray)
    ' Alway initial cap the first word; initial cap the others if
    ' they cannot be found in the "not capped" list
    If (intCounter = 0) Or (InStr(1, strNotCapped, _
    "|" & strArray(intCounter) & "|", vbTextCompare) = 0) Then
    strArray(intCounter) = StrConv(strArray(intCounter), vbProperCase)
    End If
    Next</pre>

    Or you could make it a user option... that would take several more minutes.

  7. #7
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Change Case - Title Case Problems (Word 2000 SR-3)

    Thanks for the rewrite. I didn't think about acronyms. In my case, I just all-capped a word to see what the macro would do. I did revise my code to use vbLower to first convert to lower case, but I think I'll remove it now.

    By the way, I did check my copy of The Gregg Reference Manual and it does say that It and Be should be capitalized. I guess I've always thought it looked strange.

    Thx.

    -Rich Belthoff

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Change Case - Title Case Problems (Word 2000 SR-3)

    I go by what I remember from Law Review. It's less and less every year. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •