View Single Post
 
Old 09-18-2015, 09:11 PM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following code shouldn't loop

Code:
Sub Apply_True_Title_Case_by_Style()
Dim oRng As Range
Dim oPara As Paragraph
Dim StyleName As String
Dim vFindText As Variant
Dim vReplText As Variant
Dim wrd As Integer

    StyleName = "Heading 1"
    vFindText = Array("A", "An", "And", "As", "At", "But", "By", "For", _
                      "If", "In", "Of", "On", "Or", "The", "To", "With")
    vReplText = Array("a", "an", "and", "as", "at", "but", "by", "for", _
                      "if", "in", "of", "on", "or", "the", "to", "with")

    For Each oPara In ActiveDocument.Paragraphs
        If oPara.Style = StyleName Then
            Set oRng = oPara.Range
            oRng.Case = wdTitleWord
            With oRng.Find
                For wrd = LBound(vFindText) To UBound(vFindText)
                    .Text = vFindText(wrd)
                    .Replacement.Text = vReplText(wrd)
                    .Execute MatchCase:=True, Replace:=wdReplaceAll
                Next wrd
            End With
        End If
    Next oPara
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote