Reputation: 41
Would like to ask for any advice on how to convert a sentence in to Title case with the exception of acronyms (or any words that is in all caps) in Microsoft Word. Currently my code only converts all the sentences in a specific style in Title case. Hoping you could help with with this. Thank you
Sub ChangeCase() StrFind = "K-1,K-2,K-3"
For i = 0 To UBound(Split(StrFind, ","))
With Selection.Find
.ClearFormatting
.Wrap = wdFindContinue
.Forward = True
.Format = True
.MatchWildcards = False
.Text = ""
.Style = Split(StrFind, ",")(i)
.Execute
While .Found
Selection.Range.Case = wdTitleWord
Selection.Collapse Direction:=wdCollapseEnd
.Execute
Wend
End With
Next i
End Sub
Upvotes: 0
Views: 713
Reputation: 5677
If the objective is to TitleCase words that aren't already fully capitalized, I think the below should work.
Option Explicit
Public Sub TitleCaseDocument()
Dim doc As Document: Set doc = ThisDocument
Dim wrd As Range
For Each wrd In doc.Words
If wrd.Text <> UCase$(wrd.Text) Then wrd.Case = wdTitleWord
Next
End Sub
Upvotes: 2