Change Sentence Case

M

major

Hi,

I am trying to write a macro that will change the case of all titles to
Sentence case. All titles are paragraphs that are bolded. Below is my code,
but it doesn't work. Any help would be appreciated. Thank you!

Sub TitleToSentCase()

Dim r As Range
Set r = ActiveDocument.Range
With r.Find
.Text = "(^013)"
.Font.Bold = True
.MatchWildcards = True
. Execute
Do While .Found
r.Case = wdTitleSentence
Loop
End With
End Sub
 
H

Helmut Weber

Hi,

like this:

Sub t44444()
Dim r As Range
Set r = ActiveDocument.Range
ResetSearch
With r.Find
.Text = "^p"
.Font.Bold = True
.Format = True
Do While .Execute
r.Paragraphs(1).Range.Case = wdTitleSentence
Loop
End With
ResetSearch
End Sub

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed
.Execute
End With
End Sub

You don't need wildcards at all.
And if you needed them, the parentheses
would be of no use.

..font.bold is of no use either,
unless combined with .format = true

..execute plus while .found
would give you every second bold paragraph mark
as .found triggers another search.

Plus applying titlecase to the paragraph mark only
results in nothing.

Plus make sure to reset search parameters,
otherwise you never know...

HTH

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
Top