Proper Case in VBA

VBA provides the UCase and LCase functions to convert text to upper and lower case, respectively. But what about proper case? For that, you’ll need to use the StrConv function.

StrConv(”my text here”, vbProperCase)

will return

My Text Here

Alternatively, you can use the worksheet function PROPER, like this

Application.Proper(”more proper text”)

More Proper Text

7 Comments

  1. Toad:

    Is one method inherently preferable? I guess I would have gone straight for the VBA version of the PROPER function, since I’m used to using that function already.

  2. Dick:

    Toad: I would guess that calling a worksheet function is slower than a built-in VBA function, but only marginally so. If you were concerned with speed, you would probably want StrConv, but for most applications you can use what you like.

  3. Antro:

    Maybe I’m not getting the implementation quite right, but I couldn’t get the worksheet function PROPER to work, but everything gets a little tricky when working with Excel through OLE Automation in Word. But I got the StrConv to work on first try

  4. Juan Pablo:

    Antro,

    When working from outside of Excel, you need to replace “Application” with the object variable that points to Excel, for example instead of

    Application.Proper(”more proper text”)

    you’d use

    XlApp.Proper(”more proper text”)

    and that’s the trick about it…

  5. Tramadol:

    The secret of health for both mind and body is not to mourn for the past, worry about the future, or anticipate troubles but to live in the present moment wisely and earnestly. Buy Tramadol

  6. Ed Brooks:

    It should be noted that these two functions will return different results. For the string “JAMES, P.D.” strconv will return “James, P.d”. Application.proper will return the value “James, P.D.”

    The second example is the preferred result, if you are talking about a surname followed by initials.

  7. Paddy Heron:

    When using strconv can you use a variable inside the bracets i.e.
    Strconv(TheString, vbpropercase). When I try it I am propmted with the = sign.
    Can anyone help?

Leave a comment