Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-14-2019, 08:54 AM
0rion 0rion is offline Adjust Acronym Script to include Dashes? Windows 10 Adjust Acronym Script to include Dashes? Office 2010
Novice
Adjust Acronym Script to include Dashes?
 
Join Date: Jan 2019
Posts: 11
0rion is on a distinguished road
Default Adjust Acronym Script to include Dashes?

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.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjust Acronym Script to include Dashes? Acronym Finder Macro for Microsoft Word mars1886 Word VBA 15 03-30-2022 06:56 AM
Adjust Acronym Script to include Dashes? Adding List Number to Acronym Table SerenityNetworks Word VBA 6 12-13-2016 01:36 PM
Adjust Acronym Script to include Dashes? Acronym Macro to include surrounding text SerenityNetworks Word VBA 3 03-11-2016 05:43 PM
Adjust Acronym Script to include Dashes? Acronym Finder Cray_Z Word VBA 14 09-22-2014 11:42 PM
Auto correct for Acronym mam9 Word 3 11-19-2012 01:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft