Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Macro to Change Case - but not Prepositions!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ilene - 04 May 2006 21:50 GMT
What can I add to

Selection.Range.Case = wdTitleWord

but keep Prepositions in lower case?
-----------------------------------------------------------
Thank you for your help!
ilene
Helmut Weber - 04 May 2006 22:15 GMT
Hi Ilene,

no way,

unless you set up a list of prepositions.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg Maxey - 04 May 2006 22:23 GMT
Scrap that and go with something like:
Sub TitleCaseWithLowerCase()

Application.ScreenUpdating = False

'Capitalize all words in selection
Selection.FormattedText.Case = wdTitleWord

'Uncapitalize the listed words
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

Call DoTitleCase("The ")
Call DoTitleCase("Of ")
Call DoTitleCase("And ")
Call DoTitleCase("Or ")
Call DoTitleCase("But ")
Call DoTitleCase("A ")
Call DoTitleCase("An ")
Call DoTitleCase("To ")
Call DoTitleCase("In ")
Call DoTitleCase("With ")
Call DoTitleCase("From ")
Call DoTitleCase("By ")
Call DoTitleCase("Out ")
Call DoTitleCase("That ")
Call DoTitleCase("This ")
Call DoTitleCase("For ")
Call DoTitleCase("Against ")
Call DoTitleCase("About ")
Call DoTitleCase("Between ")
Call DoTitleCase("Under ")
Call DoTitleCase("On ")
Call DoTitleCase("Up ")
Call DoTitleCase("Into ")

'Uncomment the next line if you want the selection dismissed.
'Selection.Collapse wdCollapseStart

're-capitalize first word in title
Selection.Characters(1).Case = wdUpperCase

End Sub
Sub DoTitleCase(FindText As String)
'This procedure is called from TitleCaseWithLowerCase above

Dim r As Range
Set r = Selection.Range

With Selection.Find
.ClearFormatting
.Text = FindText
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindStop
.MatchCase = True
.MatchWholeWord = True

Do While .Execute
Selection.FormattedText.Case = wdLowerCase
r.Select
Loop
End With
r.Select
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> What can I add to
>
[quoted text clipped - 4 lines]
> Thank you for your help!
> ilene
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.