-
Aug 22nd, 2008, 07:52 PM
#1
SentenceCase: Capitalize first letter of each sentence
Perhaps I still miss some features of an MS-Word's method. Please check/test. Any thought is welcome.
vb Code:
Public Function SentenceCase(sText As String) As String
Dim i As Long, bCap As Boolean, Ch As String * 1
SentenceCase = LCase(sText) '-- convert all to lowercase first
bCap = True
For i = 1 To Len(SentenceCase)
Ch = Mid$(SentenceCase, i, 1)
Select Case AscW(Ch)
Case 97 To 122 '-- a-z : separated and put on top as happens more often
If bCap Then
Mid$(SentenceCase, i, 1) = UCase(Ch)
bCap = False
End If
Case 33, 46, 63, 10, 13 '-- sentence terminators ! . ? Lf Cr
bCap = True
Case 32, 160, 9 '-- space, non-break space, tab
Case 34, 41, 93, 125, 148 '-- closing quotes or brackets
Case Is < 128 '-- other chars between 0-127
If bCap Then bCap = False
Case Else '-- Extended-Ascii (128-255) or Unicode (> 255)
If bCap Then
If StrComp(Ch, UCase(Ch), vbBinaryCompare) <> 0 Then
'-- a letter that has uppercase.
Mid$(SentenceCase, i, 1) = UCase(Ch)
End If
bCap = False
End If
End Select
Next
End Function
-
May 13th, 2009, 08:20 AM
#2
Hyperactive Member
Re: SentenceCase: Capitalize first letter of each sentence
Hm,, very neat function but it doesn't work correctly....
It capitalizes, for example, everything that comes immediately after a period. So if you have a URL in your text it capitalizes all characters in the url as well.
http://www.something.com/page.php
becomes
http://www.Something.Com/page.Php
-
Feb 6th, 2010, 02:10 PM
#3
New Member
Re: SentenceCase: Capitalize first letter of each sentence
Hi
I don't know if this would be of any help to you? It capitalizes the first letter in the sentence.
here's the post with the dll to reference
-
Feb 6th, 2010, 10:11 PM
#4
Junior Member
Re: SentenceCase: Capitalize first letter of each sentence
Originally Posted by Deliriumxx
Well, its not an intellect that determines if its a sentence or a link. nice job though.
-
Jul 17th, 2014, 05:20 PM
#5
New Member
Re: SentenceCase: Capitalize first letter of each sentence
I'm not good at VB but this is the result I want in my excel. I tried for a lot of forums for macros with this output but in vain. Can you please create a macro for MS Excel 2010 with this logic. Thanks in advance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|