Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


I need code that will Capitalize the first letter of every word

Posted on 2006-04-27
Medium Priority
Last Modified: 2010-05-01

Can someone please supply me with vb code that will take a string and convert it so that the first letter of each word is capitalized - regardless of the case of the original string?

Question by:SAbboushi
  • 3
LVL 44

Accepted Solution

bruintje earned 2000 total points
ID: 16559342
Hello SAbboushi,

you could use StrConv
StrConv("this is a test",vbProperCase)

will produce
This Is A Test

hope this helps a bit
LVL 44

Expert Comment

ID: 16559357
however if you want to prevent lowercasing the rest of the string use the tip here
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16559358
If you want to preserve the existing case of the other letters then:

Private Sub Command1_Click()
    Text1.Text = MyProperCase(Text1.Text)
End Sub

Private Function MyProperCase(ByVal str As String) As String
    Dim words As Variant
    words = Split(str, " ")
    Dim i As Integer
    For i = 0 To UBound(words)
        words(i) = UCase(Left(words(i), 1)) & Mid(words(i), 2)
    Next i
    MyProperCase = Join(words, " ")
End Function

Author Comment

ID: 16570711
Thanks for your help.
LVL 44

Expert Comment

ID: 16571258
glad i could help and thanks for the grade :)

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question