Hi,
I have data that contains dashes that I would like to abbreviate by just having the first letter of each word. I found several VBA Acronym scripts that work, but they look at the spaces so the words after the dashes get lost.
example: Projects-North America-Canada-Alberta-Moose Jaw
would yield: PAJ
I found a script that works much better:
Code:
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
Yields: PNACAMJ
Is there a way to modify this script to retain the dashes?
Desired: P-NA-C-A-MJ
Thanks.