ACRONYM

Returns the first letter of each word.


sTextThe text you want the acronym for.


REMARKS
??


Option Explicit 

Public Function ACRONYM(ByVal sText As String, _
               Optional ByVal bJustCapitals As Boolean = False) As String

Dim inextspace As Integer
Dim sfirstcharacter As String
Dim sword As String

    sText = VBA.Trim(sText)
    Do While VBA.Len(sText) > 0
       inextspace = VBA.InStr(1, sText, " ")
       If inextspace > 0 Then
          sword = VBA.Trim(VBA.Left(sText, inextspace - 1))
          sText = VBA.Right(sText, VBA.Len(sText) - inextspace)
       Else
          sword = sText
          sText = ""
       End If
       
       sfirstcharacter = VBA.Left(sword, 1)
       If bJustCapitals = True Then
          If (VBA.Asc(sfirstcharacter) >= 65 And VBA.Asc(sfirstcharacter) <= 90) Then
             ACRONYM = ACRONYM & VBA.UCase(sfirstcharacter)
          End If
       End If
       
       If bJustCapitals = False Then ACRONYM = ACRONYM & VBA.UCase(sfirstcharacter)
    Loop
End Function


Example


 

© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

PrevNext