Thanks for that, a useful bit of code. Why VB has the right case and not a sentence, this is very strange. I changed it for my purpose, because the original will not use the first letter, if there is space in front of it, I hope that you do not mind me sharing my small changes.
To remove unnecessary spaces at the beginning or at the end of a sentence, I added another function that is called from the above.
Public Function DblTrim(vString As String) As String Dim tempString As String tempString = vString Do Until Left(tempString, 1) <> " " tempString = LTrim(tempString) Loop Do Until Right(tempString, 1) <> " " tempString = RTrim(tempString) Loop DblTrim = tempString End Function Public Function ProperCaps(strIn As String) As String Dim objRegex As Object Dim objRegMC As Object Dim objRegM As Object Set objRegex = CreateObject("vbscript.regexp") strIn = DblTrim(strIn) With objRegex .Global = True .ignoreCase = True .Pattern = "(^|[\.\?\!\r\t]\s?)([az])" If .test(strIn) Then Set objRegMC = .Execute(strIn) For Each objRegM In objRegMC Mid$(strIn, objRegM.firstindex + 1, objRegM.Length) = UCase$(objRegM) Next End If ProperCaps = strIn End With End Function
You can call ProperCaps (Yourstring) to return the offer with the first letter as capital, while all spaces have been removed.
You can also use DblTrim (Yourstring) to remove all spaces at the front and back of the line (without changing the sentence), regardless of the number of spaces.
source share