Thread: [Solved] Converting casing in MS word
View Single Post
 
Old 05-12-2020, 04:10 PM
JPS0710 JPS0710 is offline Windows 10 Office 2013
Novice
 
Join Date: May 2020
Posts: 2
JPS0710 is on a distinguished road
Default Converting casing in MS word

The code below converts words in a specific style into title case, except for acronyms.

However, there are specific words that I would like to add for the exception and these words should stay in lower case format (and, for, but, etc.)

So far, this is what I came up with and currently not working:

Public Sub TitleCaseDocument()
Dim myDoc As Document: Set myDoc = ActiveDocument
Dim myPara As Word.Paragraph

For Each myPara In myDoc.StoryRanges.Item(wdMainTextStory).Paragraphs

If myPara.Style.NameLocal = "K Level 1" Then
TitleParagraph myPara
End If

Next
End Sub

Public Sub TitleParagraph(ByVal ipPara As Word.Paragraph)

Dim myText As Range
Dim Strtext As String
Strtext = "and,of"
For Each myText In ipPara.Range.Words

If Not UCase$(myText.Text) = myText.Text Then
myText.Words.Item(1).Case = wdTitleWord

Else If Not Strtext = myText.Text Then
myText.Words.Item(1).Case = wdTitleWord

End If
Next
End Sub
Reply With Quote