Results 1 to 5 of 5
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    TCase? (as in UCase(), LCase()) (Word97SR2)

    There's not much going in with title case that I can see.

    I have a need for a TCase function, similar to UCase and LCase, but can't see it in the Help files.

    When I record a macro to set Title case, I see this:
    <pre>Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 02/26/02 by Christopher Greaves
    '
    Selection.Range.Case = wdTitleWord
    End Sub
    </pre>



    Why do I need a title case? because I want a nifty macro like this one (test version only) that will coerce all folders of a directory to be Title case:
    <pre>Sub ForceDirCase()
    ' Change case of folder names to, say, TitleCase

    Dim strPathName As String
    strPathName = "d:greavesclientsa"
    Dim strDirName As String
    strDirName = Dir(strPathName, vbDirectory)

    While strDirName <> ""
    If strDirName = "." Or strDirName = ".." Then
    Else
    If (GetAttr(strPathName & strDirName) And vbDirectory) = vbDirectory Then
    '''' MsgBox strDirName
    Name strPathName & strDirName As strPathName & UCase(strDirName)
    '''' MsgBox strDirName
    Else ' it is not a folder name
    End If
    End If
    strDirName = Dir
    Wend

    End Sub
    </pre>


  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: TCase? (as in UCase(), LCase()) (Word97SR2)

    Chris,
    StrConv("blah blah", vbProperCase)?

    PS Anyone ever tell you you look a lot like Leonard Cohen?
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TCase? (as in UCase(), LCase()) (Word97SR2)

    I was "waiting for the miracle to come"

    Thank you. strConv. How did you find out about it?


    That's VBA help files falling down and not pointing to strConv in their "See Also" for the UCase/LCase functions.


    >PS Anyone ever tell you you look a lot like Leonard Cohen?

    No. because I don't. That's just his Picture up there (grin!) I write better poetry than him, though.

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: TCase? (as in UCase(), LCase()) (Word97SR2)

    "Everybody knows"? <img src=/S/grin.gif border=0 alt=grin width=15 height=15> Not sure how I found out about it originally - it's one of those things I've 'always' used. I have piece of code in my Excel toolbox for changing text to whichever case I fancy.
    Do you "sing" as well as he does though?
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TCase? (as in UCase(), LCase()) (Word97SR2)

    Here's an upgraded version for the Lounge, with thanks to Rory.

    <font color=red>CAUTION] Use at your own risk.</font color=red> The sample given here will change folder names right across drive D:


    <pre>Option Explicit
    ''
    Public Sub ForceAllDirs()
    Call ForceDirCase("d:")
    Application.StatusBar = ""
    End Sub
    ''
    Function ForceDirCase(strPathName As String)
    ' Change case of folder names to, say, TitleCase
    Application.StatusBar = strPathName
    Dim strAr() As String
    ReDim strAr(0)
    Dim strDirName As String
    strDirName = Dir(strPathName, vbDirectory)

    While strDirName <> ""
    If strDirName = "." Or strDirName = ".." Then
    Else
    If (GetAttr(strPathName & strDirName) And vbDirectory) = vbDirectory Then
    Name strPathName & strDirName As strPathName & StrConv(strDirName, vbProperCase)
    strAr(UBound(strAr)) = strPathName & strDirName & Application.PathSeparator
    ReDim Preserve strAr(UBound(strAr) + 1)
    Else ' it is not a folder name
    End If
    End If
    strDirName = Dir
    Wend
    If UBound(strAr) > 0 Then
    Dim i As Integer
    For i = 0 To UBound(strAr)
    Call ForceDirCase(strAr(i))
    Next i
    Else
    End If
    End Function
    </pre>



    > Do you "sing" as well as he does though?

    Better. And I don't use dirty words.
    I played "Bumble" in the W.A. premier of "Oliver!" in 1963.

Posting Permissions

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