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
|