Hi
Is it possible to determine from a selection whether the selection is
"TitleCase", I can detect uppercase and smallcaps but not titlecase.
Graham Mayor has an excellent post at:
https://www.microsoft.com/communiti...4a8-9a78-c594ed28407e&lang=en&cr=us&sloc=&p=1
and I could probably adapt that to detect TitleCase but is there another
technique I can apply?
I suspect not!
TIA
Ian B
This isn't perfect, but may give you some ideas:
Private Function IsTitleCase(testRg As Range) As Boolean
Dim rtn As Boolean
Dim rgWd As Range
rtn = True
For Each rgWd In testRg.Words
If (Not rgWd.Characters(1) Like "[A-Z.,!?;:]") _
And (rgWd.Characters(1) <> vbCr) Then
rtn = False
Exit For
End If
Next
IsTitleCase = rtn
End Function
Public Sub test()
If Selection.Type = wdSelectionNormal Or Selection.Type = wdSelectionIP
Then
If IsTitleCase(Selection.Sentences(1)) Then
MsgBox "Selection is title case"
Else
MsgBox "Selection is not title case"
End If
Else
MsgBox "Please select some text to test"
End If
End Sub
The idea is to test the first character of each word in the range passed
as the
parameter testRg. If any word isn't capitalized, the range is deemed to be
not
in title case. The difficulty is that the members of the collection
testRg.Words
aren't necessarily what we consider to be "words". Each punctuation
character
and paragraph mark is a separate member of the collection, so the If
condition
has to take that into account.
As an aside, this test perpetuate's Microsoft's broken idea of what
constitutes
title case. To the rest of the world, small words such as "the" or "and"
aren't
capitalized unless they're the first word of the title. At least in Word
2007
the Change Case command finally calls what it does "Capitalize Each Word"
instead of "Title Case".
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup
so all may benefit.