gramUpper

Função em VBA para substituir PRI.MAIÚSCULA do Excel, incluindo Lowercase em pronomes e Uppercase em palavras que contenham apenas consoantes e siglas conhecidas.

Function inArray(x, a) As Long
    inArray = False
    For Each i In a
        If UCase(x) = UCase(i) Then inArray = True
    Next i
End Function

Function isPronoun(word)
    pronouns = Array("E", "Da", "Do", "Das", "Dos", "De", "Em", "Para", "Com", "Sobre", "A", "O", "As", "Os", "Na", "No", "Nas", "Nos", "Desde", "Sem")
    isPronoun = inArray(word, pronouns)
End Function

Function isAcronym(word)
    vowels = Array("a", "e", "i", "o", "u")
    acronyms = Array("E&P", "CO2", "PRAVAP")
    isAcronym = True
    If inArray(word, acronyms) = False Then
        For i = 1 To Len(word)
            x = Mid(word, i, 1)
            If inArray(x, vowels) Then isAcronym = False
        Next i
    End If
End Function

Function gramUpper(txt As String) As String

For i = 0 To UBound(Split(txt, " "))
    word = Split(txt, " ")(i)
    word = UCase(Left(word, 1)) & LCase(Mid(word, 2))
    If isAcronym(word) Then word = UCase(word)
    If i > 0 Then
        If isPronoun(word) Then word = LCase(word)
    End If
    result = result & " " & word
Next i

gramUpper = Mid(result, 2)

End Function