Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-06-2011, 03:32 PM
gmaxey gmaxey is offline Is there a way to capitalize the all the words except the prepositions? Windows XP Is there a way to capitalize the all the words except the prepositions? Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,639
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Try this:

Sub RevisedTitleCase()
Dim oRng As Range
Dim arrFind() As String
Dim i As Long
Set oRng = Selection.Range
If oRng.Words.Count < 1 Then
MsgBox "Nothing selected to process. Please select text to process and try again.", vbInformation + vbOKOnly, "Nothing Selected"
Exit Sub
End If
'Apply title case
oRng.Case = wdTitleWord
'list the exceptions to look for in an array
arrFind = Split("A|An|And|As|At|But|By|For|If|In|Of|On|Or|Th e|To|With", "|")
With oRng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True
For i = LBound(arrFind) To UBound(arrFind)
.Text = arrFind(i)
.Replacement.Text = LCase(arrFind(i))
.Execute Replace:=wdReplaceAll
Next i
End With
With .Find
.Text = ": [A-Za-z]"
.MatchWildcards = True
While .Execute
oRng.Case = wdUpperCase
oRng.Collapse wdCollapseEnd
Wend
End With
Selection.Characters(1).Case = wdTitleSentence
End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why Words doesn’t show the style of the selected words automatically???? Jamal NUMAN Word 0 04-14-2011 03:20 PM
Is there a way to capitalize the all the words except the prepositions? is it possibe to capitalize every letter after a "colon space" angeltread Word VBA 4 01-17-2011 03:50 PM
Numbers in Words janak Excel 2 12-19-2010 08:53 PM
How to 'forbid' bad words? andre20 Word 5 06-14-2010 08:35 PM
capitalize first letter of sentences norco1 Word 0 06-25-2006 12:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:39 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft