View Single Post
 
Old 01-14-2019, 10:39 AM
Kenneth Hobson Kenneth Hobson is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Jun 2018
Posts: 37
Kenneth Hobson is on a distinguished road
Default

Welcome to the forum!

I don't understand that first part.

You can make these two functions into one if you like.
Code:
Sub Test()
  MsgBox abbrev("Projects-North America-Canada-Alberta-Moose Jaw")
End Sub

Function abbrev(aString$) As String
  Dim a, b, i As Integer
  a = Split(aString, "-")
  b = a
  For i = 0 To UBound(a)
    b(i) = Acronym(CStr(a(i)))
  Next i
  abbrev = Join(b, "-")
End Function

Function Acronym(str As String) As String
  Dim re As Object
  Set re = CreateObject("vbscript.regexp")
  re.Global = True
  re.Pattern = "(\w).*?(\W+|\s+|$)"
  Acronym = UCase(re.Replace(str, "$1"))
End Function
Reply With Quote